triston-notes/Cards/dev/Jest Test Boilerplate.md

16 lines
666 B
Markdown
Raw Normal View History

2023-10-21 23:52:54 +00:00
up:: [[TypeScript]]
X:: [[JavaScript]]
tags::
## Here is an example of a simple test using Jest:
```tsx
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.