16 lines
666 B
Markdown
16 lines
666 B
Markdown
|
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.
|