The blitz
dependency also automatically installs and configures jest
,
@testing-library/react
, @testing-library/react-hooks
, and
@testing-libary/jest-dom
for you.
Jest is a delightful testing framework that's simple
to use. To run tests in your app, you will run jest
or jest --watch
from the terminal.
To make a new test, make a file named something.test.ts
(or .js
,
.tsx
, etc). Here's an example:
import something from "./somewhere"
it("does something", () => {
const result = something()
expect(result).toBe(true)
})
For more details on using Jest, read the Jest documentation
Blitz provides a Jest preset that configures lots of complex things for you, including Typescript support.
If you need to
customize the jest config, you
can do so in jest.config.js
.
// jest.config.js
module.exports = {
preset: "blitz",
}
The following test files will run in the Jest server environment:
*.test.*
files inside an api
, queries
, or mutations
folder*.server.test.*
filesAll other files will run in the Jest client environment (with jsdom).
@testing-library is family of packages helps you test UI components in a user-centric way. It's a better alternative to Enzyme, if you've used that in the past.
The following packages are installed for you. Refer to their documentation as needed.