Jest
CLI
Run specific test
- pass a file pattern as the final argument
- this would match
spec/index.spec.js
- this would match
jest spec/index
- you can also filter tests by test name (not file name)
jest -t testName
Matchers
Match partial objects, arrays, strings
expect(mockFn).toHaveBeenCalledWith(
expect.objectContaining({
id: 123,
name: expect.stringContaining('sofa'),
model: expect.stringMatching(/A\d{3}/),
colors: expect.arrayContaining(['red', 'blue']),
})
)