Closed maxsu closed 1 year ago
Add a testing script: "test": "jest" 🤡
"test": "jest"
Add html testing: *@testing-library/jest-domt ref: dom testing guide
@testing-library/jest-domt
Add preact testing: @testing-library/preact ref: preact component testing guide
@testing-library/preact
Add typescript tests: ts-jest
ts-jest
Use a typescript jest.config file: ts-node
jest.config
ts-node
Add jest.config.ts:
jest.config.ts
root
transform
.ts
.tsx
testRegex
/src/__tests__/
/src/__tests__/index.ts
/src/__tests__/example.test.ts
/src/**/*.test.[ts,tsx]
/src/**/*.spec.[ts,tsx]
/src/**/test.[ts,tsx]
/src/**/spec.[ts,tsx]
moduleFileExtensions
ts
tsx
js
jsx
mjs
json
setupFilesAfterEnv
Added /srt/__tests__/example.test.ts
/srt/__tests__/example.test.ts
To run tests, perform npm test.
npm test
Breaking Changes: None.
Add a testing script:
"test": "jest"
🤡Add html testing: *
@testing-library/jest-domt
ref: dom testing guideAdd preact testing:
@testing-library/preact
ref: preact component testing guideAdd typescript tests:
ts-jest
Use a typescript
jest.config
file:ts-node
Add
jest.config.ts
:root
: The project's import root is /srctransform
: Translate.ts
/.tsx
tests usingts-jest
testRegex
: Tests files are.ts
/.tsx
file in/src/__tests__/
(for example:/src/__tests__/index.ts
,/src/__tests__/example.test.ts
)/src/**/*.test.[ts,tsx]
/src/**/*.spec.[ts,tsx]
/src/**/test.[ts,tsx]
/src/**/spec.[ts,tsx]
moduleFileExtensions
: Jest tests may importts
,tsx
,js
,jsx
,mjs
, andjson
modules, and also node binary modules.setupFilesAfterEnv
: install jest-dom for each test moduleAdded
/srt/__tests__/example.test.ts
To run tests, perform
npm test
.Breaking Changes: None.