Package Exports
- jest-cli
- jest-cli/bin/jest
- jest-cli/bin/jest.js
- jest-cli/package.json
- jest-cli/src/jest
- 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 the Jasmine test framework, using familiar expect(value).toBe(other) assertions
Mock by Default: Automatically mocks CommonJS modules returned by require(), making most existing code testable
Short Feedback Loop: DOM APIs are mocked and tests run in parallel via a small node.js command line utility
Getting Started
Check out the Getting Started tutorial. It's pretty simple!
API
jest.addMatchers(matchers)
jest.autoMockOff()
jest.autoMockOn()
jest.clearAllTimers()
jest.currentTestPath()
jest.fn(implementation?)
jest.genMockFromModule(moduleName)
jest.mock(moduleName)
jest.runAllTicks()
jest.runAllTimers()
jest.runOnlyPendingTimers()
jest.setMock(moduleName, moduleExports)
jest.unmock(moduleName)
Mock functions
Mock functions can be created using jest.fn()
.
mockFn.mock.calls
mockFn.mock.instances
mockFn.mockClear()
mockFn.mockImplementation(fn)
mockFn.mockReturnThis()
mockFn.mockReturnValue(value)
mockFn.mockReturnValueOnce(value)
require extensions
Config options
config.automock
[boolean]config.bail
[boolean]config.cache
[boolean]config.cacheDirectory
[string]config.collectCoverage
[boolean]config.collectCoverageOnlyFrom
[object]config.globals
[object]config.mocksPattern
[string]config.moduleFileExtensions
[array] config.modulePathIgnorePatterns
[array] config.moduleNameMapper
[object<string, string>]config.preprocessCachingDisabled
[boolean]config.rootDir
[string]config.scriptPreprocessor
[string]config.preprocessorIgnorePatterns
[array] config.setupFiles
[array]config.setupTestFrameworkScriptFile
[string]config.testDirectoryName
[string]config.testFileExtensions
[array] config.testPathDirs
[array] config.testPathIgnorePatterns
[array] config.testPathPattern
[string]config.testRunner
[string]config.unmockedModulePathPatterns
[array] config.verbose
[boolean]config.watchman
[boolean]
Globally injected variables
afterEach(fn)
beforeEach(fn)
describe(name, fn)
expect(value)
it(name, fn)
it.only(name, fn)
executes only this test. Useful when investigating a failurejest
pit(name, fn)
helper for promisesrequire(module)
require.requireActual(module)
xdescribe(name, fn)
xit(name, fn)
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)