tests.md 1.14 KB
Newer Older
1 2 3 4 5
Frontend tests
======

*Rex-DRI* comes in with several *tests* that you can perform locally using the commands `make test_backend` and `make test_frontend` once the project is up and running (`make up`).

6
?> :information_desk_person: As of now, the frontend tests only concern specific functions and not react components.
7

8
The frontend tests are performed with `jest` framework and are contained in the `frontend/tests` directory. For your tests to be taken into account, the file name must end with `.test.js`.
9

10
To create tests, the syntaxe is fairly simple:
11

12 13 14 15 16 17
```js
test("parse empty string", () => {
  const str = "";
  expect(parseMoney(str).length).toBe(0);
});
```
18

19 20 21 22 23
You simply need to wrap your test in the `test` function (no need to import it, it will be provided automatically when testing). This function takes the name of your test as first argument and a function to execute as second argument.

Inside the second argument function you can use the wrapper `expect` and then use the `toBe` attribute to check that what is returned is something specific.

Don't miss the [`jest` documentation](https://jestjs.io/docs/en/getting-started) for more examples.