Skip to content

Instantly share code, notes, and snippets.

@eralston
Last active July 15, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eralston/177bfa4f988633071fafd173a8db163f to your computer and use it in GitHub Desktop.
Save eralston/177bfa4f988633071fafd173a8db163f to your computer and use it in GitHub Desktop.
Jest Cheat Sheet
// 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