Last active
July 15, 2020 20:11
-
-
Save eralston/177bfa4f988633071fafd173a8db163f to your computer and use it in GitHub Desktop.
Jest Cheat Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// package.json | |
{ | |
... | |
"scripts": { | |
"test": "NODE_ENV=test jest --ci --verbose", | |
}, | |
... | |
"devDependencies": { | |
"@types/jest": "^26.0.3", | |
"babel-jest": "^26.1.0", | |
"moq.ts": "^6.4.0", | |
"jest": "^26.1.0", | |
}, | |
... | |
} | |
// jest.config.js | |
const { defaults } = require('jest-config') | |
module.exports = { | |
collectCoverage: true, | |
collectCoverageFrom: [ | |
'src/*.{js,ts}', | |
'!**/node_modules/**' | |
], | |
coverageReporters: [ | |
'text', | |
'cobertura', | |
'html' | |
], | |
moduleFileExtensions: [ | |
...defaults.moduleFileExtensions, | |
'ts', | |
'tsx' | |
], | |
moduleNameMapper: { | |
'@src/(.*)': '<rootDir>/src/$1', | |
'@tests/(.*)': '<rootDir>/tests/$1' | |
} | |
} | |
// example.test.js | |
import { Mock } from 'moq.ts' | |
describe('who tests the tests?', () => { | |
it('can run a test', async () => { | |
expect.hasAssertions() | |
const result = // test something | |
expect(result.input).toBe('TESTED') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment