E2E & Performance Testing

Preview — 3 of 10 questions

What does the testing pyramid suggest about test distribution?

javascript
E2E Tests (5-10%)
       /\
      /  \
     /    \
    / Integ\
   /  Tests\
  / (15-30%)\
 /___________\
  Unit Tests
   (60-80%)
AWrite equal numbers of unit, integration, and end-to-end tests.
BMany unit tests (base), fewer integration tests (middle), fewer end-to-end tests (top).
CMost tests should be end-to-end tests.
DTesting pyramid is outdated.

What is snapshot testing?

javascript
// First run: Snapshot is created
test("should render user profile", () => {
  const profile = renderUserProfile({ name: "Alice", age: 30 });
  expect(profile).toMatchSnapshot();
  // Snapshot created with current output
});

// Snapshot file (created automatically)
// __snapshots__/user.test.js.snap
/*
exports[`should render user profile 1`] = `
<div>
  <h1>Alice</h1>
  <p>Age: 30</p>
</div>
`;
*/

// Future runs: Compare against snapshot
// If output changes, test fails and shows diff
ATaking a screenshot of the UI.
BCapturing the output of a function and comparing future outputs to it.
CTesting only image files.
DA backup of your test files.

What tools can you use to debug JavaScript performance issues?

javascript
performance.mark("start");
// Code to measure
performance.mark("end");
performance.measure("duration", "start", "end");

const measure = performance.getEntriesByName("duration")[0];
console.log(`Duration: ${measure.duration}ms`);
AConsole.log is enough.
BPerformance API, Lighthouse, DevTools profiler, WebPageTest.
CPerformance issues cannot be debugged.
DOnly browser extensions.

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.