0
0
Cypresstesting~20 mins

Code coverage plugin in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Code Coverage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Understanding code coverage report output
Given the following Cypress test and code coverage setup, what will be the coverage percentage reported for the function add after running the test?
Cypress
function add(a, b) {
  if (a === 0) {
    return b;
  }
  return a + b;
}

describe('add function', () => {
  it('returns b when a is zero', () => {
    expect(add(0, 5)).to.equal(5);
  });
});
A50%
B100%
C0%
D75%
Attempts:
2 left
💡 Hint
Think about which lines of the function are executed by the test.
assertion
intermediate
1:30remaining
Correct assertion for coverage threshold
Which assertion correctly checks that the global coverage object reports at least 80% statement coverage in Cypress tests?
Cypress
/* Assume global coverage object is available as window.__coverage__ */
Aassert(window.__coverage__.statements >= 80);
Bexpect(window.__coverage__.statements.percent).to.be.above(80);
Cexpect(window.__coverage__.statements.pct).to.be.gte(80);
Dexpect(window.__coverage__.statements.pct).to.equal(80);
Attempts:
2 left
💡 Hint
Check the property name for statement coverage percentage in the coverage object.
🔧 Debug
advanced
2:00remaining
Debugging missing coverage data
You configured Cypress with the code coverage plugin, but after running tests, the coverage report is empty. Which of the following is the most likely cause?
AThe test files are missing the <code>describe</code> blocks.
BThe <code>cy.visit()</code> command is missing in tests.
CThe coverage report folder path is incorrect in <code>cypress.json</code>.
DThe instrumented code is not loaded during tests.
Attempts:
2 left
💡 Hint
Think about what code coverage measures and what must happen for it to collect data.
framework
advanced
2:30remaining
Configuring Cypress code coverage plugin
Which configuration snippet correctly sets up the Cypress code coverage plugin to collect coverage and generate reports after tests?
A
module.exports = {
  e2e: {
    setupNodeEvents(on, config) {
      require('cypress-plugin-code-coverage')(on, config);
      return config;
    }
  }
};
B
module.exports = {
  e2e: {
    setupNodeEvents(on, config) {
      require('@cypress/code-coverage/task')(on, config);
      return config;
    }
  }
};
C
module.exports = {
  e2e: {
    setupNodeEvents(on, config) {
      on('before:run', () =&gt; console.log('Starting tests'));
      return config;
    }
  }
};
D
module.exports = {
  e2e: {
    setupNodeEvents(on, config) {
      require('@cypress/code-coverage')(on, config);
      return config;
    }
  }
};
Attempts:
2 left
💡 Hint
Check the exact package name and method to register the coverage task.
🧠 Conceptual
expert
3:00remaining
Impact of source maps on coverage accuracy
Why are source maps important when using the Cypress code coverage plugin with transpiled code (e.g., TypeScript or Babel)?
AThey map the transpiled code back to original source lines, ensuring accurate coverage reporting.
BThey speed up test execution by caching coverage data.
CThey automatically fix syntax errors in the transpiled code.
DThey enable Cypress to run tests in multiple browsers simultaneously.
Attempts:
2 left
💡 Hint
Think about how coverage tools relate executed code to original source code.