Unit Test - Setup
We're using Jest and React Testing Library to test our modules. Using these libraries most of the time is enough (we'll see more in mocking section for advanced use cases).
For most cases, you don't need to do anything. Our jest config will automatically pick up your new packages and add it to Jest multi projects. If you need more customization you can create jest.config.js in root directory of your package.
// packages/sample/app-mobile/jest.config.js
module.exports = {
preset: '@traveloka/core',
// this is optional but you'll get better visibility when running test
// for entire projects
displayName: 'sample-mobile',
};
Running Test
The recommendation is to use watch mode which by default only run test for files that just recently changed. Alternatively, you can specify path directly to matching test files.
# watch entire project, only run test for files that recently changed
pnpm test --watch
# or run test for specific file
pnpm test sample/data
# or combine them
pnpm test sample/data --watch