triston-notes/Cards/dev/Jest Test Boilerplate.md
2023-10-21 18:52:54 -05:00

666 B

up:: TypeScript X:: JavaScript tags::

Here is an example of a simple test using Jest:

const add = (a, b) => a + b;

test('adds 1 + 2 to equal 3', () => {
  expect(add(1, 2)).toBe(3);
});

In this example, add is a simple function that takes two numbers and returns their sum. The test uses the test method provided by Jest to create a test case, which checks that calling add with the arguments 1 and 2 returns the expected result of 3. The test uses the expect method provided by Jest to make the assertion, and the toBe matcher to check that the actual value is equal to the expected value.