codejump

Unit Testing

Preview — 3 of 10 questions

What best describes unit testing?

javascript
// Function to test
function add(a, b) {
  return a + b;
}

// Unit test
test("add function should return sum of two numbers", () => {
  expect(add(2, 3)).toBe(5);
  expect(add(-1, 1)).toBe(0);
  expect(add(0, 0)).toBe(0);
});
ATesting an entire application end-to-end.
BTesting individual units/functions in isolation to verify they work correctly.
CTesting only the user interface.
DTesting code only in production.

Which of the following is a JavaScript test framework?

javascript
// test.js
describe("Math operations", () => {
  test("should add two numbers", () => {
    expect(2 + 2).toBe(4);
  });
});
AReact
BNode.js
CExpress
DJest

What is an assertion in testing?

javascript
expect(value).toBe(expectedValue);        // Strict equality
expect(value).toEqual(expectedValue);     // Deep equality
expect(value).toBeTruthy();               // Is truthy
expect(value).toBeFalsy();                // Is falsy
expect(array).toContain(item);            // Array contains item
expect(function).toThrow();               // Function throws error
expect(number).toBeGreaterThan(5);        // Greater than
AA statement that verifies a value is what you expect it to be.
BA statement that declares what a variable should be.
CAn error message.
DA test file.

Sign up free to play

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