Package Exports
- jest-cli/bin/jest
- jest-cli/bin/jest.js
- jest-cli/package.json
- jest-cli/src/lib/moduleMocker
- jest-cli/src/lib/utils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jest-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Jest
Painless JavaScript Unit Testing
Familiar Approach: Built on top of Jasmine test framework, a familiar BDD testing environment
Mock by Default: Automatically mocks CommonJS modules returned by require(), making most existing code testable
Short Feedback Loop: Tests run in parallel and DOM apis are mocked so you can run tests on the command line
Take a look at the website for more information
Getting Started
Getting started with Jest is pretty simple. All you need to do is:
- Write some (jasmine) tests in a
__tests__/
directory - Run
npm install jest-cli --save-dev
- Add
"scripts": {"test": "jest"}
to yourpackage.json
- Run
npm test
This will run your automatically mocked tests for you and you'll be on your way!
Check out the Getting Started tutorial for more in-depth details.
API
jest.autoMockOff()
jest.autoMockOn()
jest.clearAllTimers()
jest.dontMock(module)
jest.genMockFromModule(moduleObj)
jest.genMockFunction()
jest.genMockFn()
jest.mock(moduleName)
jest.runAllTicks()
jest.runAllTimers()
jest.runOnlyPendingTimers()
jest.setMock(moduleName, moduleExports)
Mock functions
mockFn.mock.calls
mockFn.mock.instances
mockFn.mockClear()
mockFn.mockImplementation(fn)
mockFn.mockImpl(fn)
mockFn.mockReturnThis()
mockFn.mockReturnValue(value)
mockFn.mockReturnValueOnce(value)
Config options
config.collectCoverage
[boolean]config.collectCoverageOnlyFrom
[object]config.modulePathIgnorePatterns
[array] config.rootDir
[string]config.scriptPreprocessor
[string]config.setupEnvScriptFile
[string]config.setupTestFrameworkScriptFile
[string]config.testFileExtensions
[array] config.testPathDirs
[array] config.testPathIgnorePatterns
[array] config.unmockedModulePathPatterns
[array]
Globally injected variables
jest
require(module)
require.requireActual(module)
describe(name, fn)
beforeEach(fn)
afterEach(fn)
it(name, fn)
it.only(name, fn)
executes only this test. Useful when investigating a failurepit(name, fn)
helper for promises
expect(value)
.not
inverse the next comparison.toThrow(?message)
.toBe(value)
comparison using===
.toEqual(value)
deep comparison. Usejasmine.any(type)
to be softer.toBeFalsy()
.toBeTruthy()
.toBeNull()
.toBeUndefined()
.toBeDefined()
.toMatch(regexp)
.toContain(string)
.toBeCloseTo(number, delta)
.toBeGreaterThan(number)
.toBeLessThan(number)
.toBeCalled()
.toBeCalledWith(arg, um, ents)
.lastCalledWith(arg, um, ents)