@zanminkian/powerful-jest
@zanminkian/powerful-jest
is nowtyped-jest
. Usetyped-jest
instead.
Empower your Jest testing experience.
Features
- 100% compatible with Jest. Use
@zanminkian/powerful-jest
just like you would usejest
. - Out-of-the-box TypeScript support.
- Sensible defaults adhering to best practices. Most projects work seamlessly with zero configuration.
- Integrated supertest in it.
Usage
- Uninstall
jest
,@types/jest
, andts-jest
if they are already installed in your project.
pnpm remove jest @types/jest ts-jest
- Install
@zanminkian/powerful-jest
.
pnpm add -D @zanminkian/powerful-jest
- Create an
app.ts
file.
import express from 'express'
const app = express()
app.use((req, res) => {
res.json({ hello: 'world' })
})
export default app
- Create an
app.spec.ts
file.
import { describe, beforeEach, it, expect, supertest } from '@zanminkian/powerful-jest'
import app from './app'
describe('app', () => {
beforeEach(() => {
// This will be executed before each test case.
})
afterEach(() => {
jest.resetAllMocks()
})
it('should be 2', () => {
expect(1 + 1).toBe(2)
})
it('should success', () => {
supertest(app).get('/').expect({ hello: 'world' })
})
})
- Run
pnpm jest
to execute tests.
Configuration
- Add more CLI configurations after the
pnpm jest
command. For example, runpnpm jest --coverage
to collect test coverage. Runpnpm jest -h
for more CLI options information. - Add a
jest.config.js
file in the root of your project. Consult the official Jest documentation for more information.
How it works
If you don't include CLI options when running pnpm jest
, we will append some sensible defaults:
-
--transform='{"^.+\\\\.tsx?$":"ts-jest"}'
: This option transforms TypeScript files, so you can support TypeScript projects without additional configurations or installations. -
--passWithNoTests
: This option prevents the CLI from producing errors if no tests are found. You can override this default bypnpm jest --passWithNoTests=false
. -
--collectCoverageFrom='**/src/**/*.{(j|t)s,(j|t)sx}'
: This option specifies the location for collecting test coverage. Override it as needed:pnpm jest --collectCoverageFrom='**/lib/**/*.js'
License
MIT