Update jest flow type to latest v23

Summary: Copied https://raw.githubusercontent.com/flow-typed/flow-typed/master/definitions/npm/jest_v23.x.x/flow_v0.39.x-/jest_v23.x.x.js

Reviewed By: yungsters

Differential Revision: D9762910

fbshipit-source-id: 626c456ea51ca636194a56f6b0878b66b7fb3842
This commit is contained in:
Spencer Ahrens 2018-09-11 11:06:44 -07:00 committed by Facebook Github Bot
parent 159adfb826
commit 09e6e6c329
1 changed files with 614 additions and 109 deletions

View File

@ -4,20 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* Modified from https://raw.githubusercontent.com/flowtype/flow-typed/b43dff3e0ed5ccf7033839045f4819e8db40faa9/definitions/npm/jest_v20.x.x/flow_v0.22.x-/jest_v20.x.x.js
* Duplicated from www/flow/shared/jest.js
* List of modifications:
* - added function fail
* - added jest.requireActual
* - added jest.requireMock
* - added JestMockFn.mockName
* - added JestMockFn.mockRejectedValue
* - added JestMockFn.mockRejectedValueOnce
* - added JestMockFn.mockResolvedValue
* - added JestMockFn.mockResolvedValueOnce
* - added JestMockFn.mock.thrownErrors
* - added JestMockFn.mock.returnValues
* - added jest.setTimeout
* Copied from https://raw.githubusercontent.com/flow-typed/flow-typed/master/definitions/npm/jest_v23.x.x/flow_v0.39.x-/jest_v23.x.x.js
* @flow strict
* @format
*/
@ -42,10 +29,10 @@ type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
*/
instances: Array<TReturn>,
/**
* An array containing the results of a method, and whether they were
* returned or thrown.
* An array that contains all the object results that have been
* returned by this mock function call
*/
results: Array<{isThrown: boolean}>,
results: Array<{ isThrow: boolean, value: TReturn }>
},
/**
* Resets all information stored in the mockFn.mock.calls and
@ -73,7 +60,7 @@ type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
* will also be executed when the mock is called.
*/
mockImplementation(
fn: (...args: TArguments) => TReturn,
fn: (...args: TArguments) => TReturn
): JestMockFn<TArguments, TReturn>,
/**
* Accepts a function that will be used as an implementation of the mock for
@ -81,48 +68,48 @@ type JestMockFn<TArguments: $ReadOnlyArray<*>, TReturn> = {
* calls produce different results.
*/
mockImplementationOnce(
fn: (...args: TArguments) => TReturn,
fn: (...args: TArguments) => TReturn
): JestMockFn<TArguments, TReturn>,
/**
* Accepts a string to use in test result output in place of "jest.fn()" to
* indicate which mock function is being referenced.
*/
mockName(name: string): JestMockFn<TArguments, TReturn>,
/**
* Sugar for: jest.fn().mockReturnValue(Promise.reject(value));
*/
mockRejectedValue(value: TReturn): JestMockFn<TArguments, TReturn>,
/**
* Sugar for: jest.fn().mockReturnValueOnce(Promise.reject(value));
*/
mockRejectedValueOnce(value: TReturn): JestMockFn<TArguments, TReturn>,
/**
* Sugar for: jest.fn().mockReturnValue(Promise.resolve(value));
*/
mockResolvedValue(value: TReturn): JestMockFn<TArguments, TReturn>,
/**
* Sugar for: jest.fn().mockReturnValueOnce(Promise.resolve(value));
*/
mockResolvedValueOnce(value: TReturn): JestMockFn<TArguments, TReturn>,
/**
* Just a simple sugar function for returning `this`
*/
mockReturnThis(): void,
/**
* Deprecated: use jest.fn(() => value) instead
* Accepts a value that will be returned whenever the mock function is called.
*/
mockReturnValue(value: TReturn): JestMockFn<TArguments, TReturn>,
/**
* Sugar for only returning a value once inside your mock
*/
mockReturnValueOnce(value: TReturn): JestMockFn<TArguments, TReturn>,
/**
* Sugar for jest.fn().mockImplementation(() => Promise.resolve(value))
*/
mockResolvedValue(value: TReturn): JestMockFn<TArguments, Promise<TReturn>>,
/**
* Sugar for jest.fn().mockImplementationOnce(() => Promise.resolve(value))
*/
mockResolvedValueOnce(value: TReturn): JestMockFn<TArguments, Promise<TReturn>>,
/**
* Sugar for jest.fn().mockImplementation(() => Promise.reject(value))
*/
mockRejectedValue(value: TReturn): JestMockFn<TArguments, Promise<any>>,
/**
* Sugar for jest.fn().mockImplementationOnce(() => Promise.reject(value))
*/
mockRejectedValueOnce(value: TReturn): JestMockFn<TArguments, Promise<any>>
};
type JestAsymmetricEqualityType = {
/**
* A custom Jasmine equality tester
*/
asymmetricMatch(value: mixed): boolean,
asymmetricMatch(value: mixed): boolean
};
type JestCallsType = {
@ -132,22 +119,24 @@ type JestCallsType = {
count(): number,
first(): mixed,
mostRecent(): mixed,
reset(): void,
reset(): void
};
type JestClockType = {
install(): void,
mockDate(date: Date): void,
tick(milliseconds?: number): void,
uninstall(): void,
uninstall(): void
};
type JestMatcherResult = {
message?: string | (() => string),
pass: boolean,
pass: boolean
};
type JestMatcher = (actual: any, expected: any) => JestMatcherResult;
type JestMatcher = (actual: any, expected: any) =>
| JestMatcherResult
| Promise<JestMatcherResult>;
type JestPromiseType = {
/**
@ -159,7 +148,37 @@ type JestPromiseType = {
* Use resolves to unwrap the value of a fulfilled promise so any other
* matcher can be chained. If the promise is rejected the assertion fails.
*/
resolves: JestExpectType,
resolves: JestExpectType
};
/**
* Jest allows functions and classes to be used as test names in test() and
* describe()
*/
type JestTestName = string | Function;
/**
* Plugin: jest-styled-components
*/
type JestStyledComponentsMatcherValue =
| string
| JestAsymmetricEqualityType
| RegExp
| typeof undefined;
type JestStyledComponentsMatcherOptions = {
media?: string;
modifier?: string;
supports?: string;
}
type JestStyledComponentsMatchersType = {
toHaveStyleRule(
property: string,
value: JestStyledComponentsMatcherValue,
options?: JestStyledComponentsMatcherOptions
): void,
};
/**
@ -169,24 +188,366 @@ type EnzymeMatchersType = {
toBeChecked(): void,
toBeDisabled(): void,
toBeEmpty(): void,
toBeEmptyRender(): void,
toBePresent(): void,
toContainReact(element: React$Element<any>): void,
toExist(): void,
toHaveClassName(className: string): void,
toHaveHTML(html: string): void,
toHaveProp(propKey: string, propValue?: any): void,
toHaveProp: ((propKey: string, propValue?: any) => void) & ((props: Object) => void),
toHaveRef(refName: string): void,
toHaveState(stateKey: string, stateValue?: any): void,
toHaveStyle(styleKey: string, styleValue?: any): void,
toHaveState: ((stateKey: string, stateValue?: any) => void) & ((state: Object) => void),
toHaveStyle: ((styleKey: string, styleValue?: any) => void) & ((style: Object) => void),
toHaveTagName(tagName: string): void,
toHaveText(text: string): void,
toIncludeText(text: string): void,
toHaveValue(value: any): void,
toMatchElement(element: React$Element<any>): void,
toMatchSelector(selector: string): void,
toMatchSelector(selector: string): void
};
type JestExpectType = {
not: JestExpectType & EnzymeMatchersType,
// DOM testing library extensions https://github.com/kentcdodds/dom-testing-library#custom-jest-matchers
type DomTestingLibraryType = {
toBeInTheDOM(): void,
toHaveTextContent(content: string): void,
toHaveAttribute(name: string, expectedValue?: string): void
};
// Jest JQuery Matchers: https://github.com/unindented/custom-jquery-matchers
type JestJQueryMatchersType = {
toExist(): void,
toHaveLength(len: number): void,
toHaveId(id: string): void,
toHaveClass(className: string): void,
toHaveTag(tag: string): void,
toHaveAttr(key: string, val?: any): void,
toHaveProp(key: string, val?: any): void,
toHaveText(text: string | RegExp): void,
toHaveData(key: string, val?: any): void,
toHaveValue(val: any): void,
toHaveCss(css: {[key: string]: any}): void,
toBeChecked(): void,
toBeDisabled(): void,
toBeEmpty(): void,
toBeHidden(): void,
toBeSelected(): void,
toBeVisible(): void,
toBeFocused(): void,
toBeInDom(): void,
toBeMatchedBy(sel: string): void,
toHaveDescendant(sel: string): void,
toHaveDescendantWithText(sel: string, text: string | RegExp): void
};
// Jest Extended Matchers: https://github.com/jest-community/jest-extended
type JestExtendedMatchersType = {
/**
* Note: Currently unimplemented
* Passing assertion
*
* @param {String} message
*/
// pass(message: string): void;
/**
* Note: Currently unimplemented
* Failing assertion
*
* @param {String} message
*/
// fail(message: string): void;
/**
* Use .toBeEmpty when checking if a String '', Array [] or Object {} is empty.
*/
toBeEmpty(): void;
/**
* Use .toBeOneOf when checking if a value is a member of a given Array.
* @param {Array.<*>} members
*/
toBeOneOf(members: any[]): void;
/**
* Use `.toBeNil` when checking a value is `null` or `undefined`.
*/
toBeNil(): void;
/**
* Use `.toSatisfy` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean`.
* @param {Function} predicate
*/
toSatisfy(predicate: (n: any) => boolean): void;
/**
* Use `.toBeArray` when checking if a value is an `Array`.
*/
toBeArray(): void;
/**
* Use `.toBeArrayOfSize` when checking if a value is an `Array` of size x.
* @param {Number} x
*/
toBeArrayOfSize(x: number): void;
/**
* Use `.toIncludeAllMembers` when checking if an `Array` contains all of the same members of a given set.
* @param {Array.<*>} members
*/
toIncludeAllMembers(members: any[]): void;
/**
* Use `.toIncludeAnyMembers` when checking if an `Array` contains any of the members of a given set.
* @param {Array.<*>} members
*/
toIncludeAnyMembers(members: any[]): void;
/**
* Use `.toSatisfyAll` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean` for all values in an array.
* @param {Function} predicate
*/
toSatisfyAll(predicate: (n: any) => boolean): void;
/**
* Use `.toBeBoolean` when checking if a value is a `Boolean`.
*/
toBeBoolean(): void;
/**
* Use `.toBeTrue` when checking a value is equal (===) to `true`.
*/
toBeTrue(): void;
/**
* Use `.toBeFalse` when checking a value is equal (===) to `false`.
*/
toBeFalse(): void;
/**
* Use .toBeDate when checking if a value is a Date.
*/
toBeDate(): void;
/**
* Use `.toBeFunction` when checking if a value is a `Function`.
*/
toBeFunction(): void;
/**
* Use `.toHaveBeenCalledBefore` when checking if a `Mock` was called before another `Mock`.
*
* Note: Required Jest version >22
* Note: Your mock functions will have to be asynchronous to cause the timestamps inside of Jest to occur in a differentJS event loop, otherwise the mock timestamps will all be the same
*
* @param {Mock} mock
*/
toHaveBeenCalledBefore(mock: JestMockFn<any, any>): void;
/**
* Use `.toBeNumber` when checking if a value is a `Number`.
*/
toBeNumber(): void;
/**
* Use `.toBeNaN` when checking a value is `NaN`.
*/
toBeNaN(): void;
/**
* Use `.toBeFinite` when checking if a value is a `Number`, not `NaN` or `Infinity`.
*/
toBeFinite(): void;
/**
* Use `.toBePositive` when checking if a value is a positive `Number`.
*/
toBePositive(): void;
/**
* Use `.toBeNegative` when checking if a value is a negative `Number`.
*/
toBeNegative(): void;
/**
* Use `.toBeEven` when checking if a value is an even `Number`.
*/
toBeEven(): void;
/**
* Use `.toBeOdd` when checking if a value is an odd `Number`.
*/
toBeOdd(): void;
/**
* Use `.toBeWithin` when checking if a number is in between the given bounds of: start (inclusive) and end (exclusive).
*
* @param {Number} start
* @param {Number} end
*/
toBeWithin(start: number, end: number): void;
/**
* Use `.toBeObject` when checking if a value is an `Object`.
*/
toBeObject(): void;
/**
* Use `.toContainKey` when checking if an object contains the provided key.
*
* @param {String} key
*/
toContainKey(key: string): void;
/**
* Use `.toContainKeys` when checking if an object has all of the provided keys.
*
* @param {Array.<String>} keys
*/
toContainKeys(keys: string[]): void;
/**
* Use `.toContainAllKeys` when checking if an object only contains all of the provided keys.
*
* @param {Array.<String>} keys
*/
toContainAllKeys(keys: string[]): void;
/**
* Use `.toContainAnyKeys` when checking if an object contains at least one of the provided keys.
*
* @param {Array.<String>} keys
*/
toContainAnyKeys(keys: string[]): void;
/**
* Use `.toContainValue` when checking if an object contains the provided value.
*
* @param {*} value
*/
toContainValue(value: any): void;
/**
* Use `.toContainValues` when checking if an object contains all of the provided values.
*
* @param {Array.<*>} values
*/
toContainValues(values: any[]): void;
/**
* Use `.toContainAllValues` when checking if an object only contains all of the provided values.
*
* @param {Array.<*>} values
*/
toContainAllValues(values: any[]): void;
/**
* Use `.toContainAnyValues` when checking if an object contains at least one of the provided values.
*
* @param {Array.<*>} values
*/
toContainAnyValues(values: any[]): void;
/**
* Use `.toContainEntry` when checking if an object contains the provided entry.
*
* @param {Array.<String, String>} entry
*/
toContainEntry(entry: [string, string]): void;
/**
* Use `.toContainEntries` when checking if an object contains all of the provided entries.
*
* @param {Array.<Array.<String, String>>} entries
*/
toContainEntries(entries: [string, string][]): void;
/**
* Use `.toContainAllEntries` when checking if an object only contains all of the provided entries.
*
* @param {Array.<Array.<String, String>>} entries
*/
toContainAllEntries(entries: [string, string][]): void;
/**
* Use `.toContainAnyEntries` when checking if an object contains at least one of the provided entries.
*
* @param {Array.<Array.<String, String>>} entries
*/
toContainAnyEntries(entries: [string, string][]): void;
/**
* Use `.toBeExtensible` when checking if an object is extensible.
*/
toBeExtensible(): void;
/**
* Use `.toBeFrozen` when checking if an object is frozen.
*/
toBeFrozen(): void;
/**
* Use `.toBeSealed` when checking if an object is sealed.
*/
toBeSealed(): void;
/**
* Use `.toBeString` when checking if a value is a `String`.
*/
toBeString(): void;
/**
* Use `.toEqualCaseInsensitive` when checking if a string is equal (===) to another ignoring the casing of both strings.
*
* @param {String} string
*/
toEqualCaseInsensitive(string: string): void;
/**
* Use `.toStartWith` when checking if a `String` starts with a given `String` prefix.
*
* @param {String} prefix
*/
toStartWith(prefix: string): void;
/**
* Use `.toEndWith` when checking if a `String` ends with a given `String` suffix.
*
* @param {String} suffix
*/
toEndWith(suffix: string): void;
/**
* Use `.toInclude` when checking if a `String` includes the given `String` substring.
*
* @param {String} substring
*/
toInclude(substring: string): void;
/**
* Use `.toIncludeRepeated` when checking if a `String` includes the given `String` substring the correct number of times.
*
* @param {String} substring
* @param {Number} times
*/
toIncludeRepeated(substring: string, times: number): void;
/**
* Use `.toIncludeMultiple` when checking if a `String` includes all of the given substrings.
*
* @param {Array.<String>} substring
*/
toIncludeMultiple(substring: string[]): void;
};
interface JestExpectType {
not:
& JestExpectType
& EnzymeMatchersType
& DomTestingLibraryType
& JestJQueryMatchersType
& JestStyledComponentsMatchersType
& JestExtendedMatchersType,
/**
* If you have a mock function, you can use .lastCalledWith to test what
* arguments it was last called with.
@ -197,10 +558,6 @@ type JestExpectType = {
* strict equality.
*/
toBe(value: any): void,
/**
* Use .toHaveBeenCalled to ensure that a mock function got called.
*/
toBeCalled(): void,
/**
* Use .toBeCalledWith to ensure that a mock function was called with
* specific arguments.
@ -276,21 +633,55 @@ type JestExpectType = {
* Use .toHaveBeenCalled to ensure that a mock function got called.
*/
toHaveBeenCalled(): void,
toBeCalled(): void;
/**
* Use .toHaveBeenCalledTimes to ensure that a mock function got called exact
* number of times.
*/
toHaveBeenCalledTimes(number: number): void,
toBeCalledTimes(number: number): void;
/**
*
*/
toHaveBeenNthCalledWith(nthCall: number, ...args: Array<any>): void;
nthCalledWith(nthCall: number, ...args: Array<any>): void;
/**
*
*/
toHaveReturned(): void;
toReturn(): void;
/**
*
*/
toHaveReturnedTimes(number: number): void;
toReturnTimes(number: number): void;
/**
*
*/
toHaveReturnedWith(value: any): void;
toReturnWith(value: any): void;
/**
*
*/
toHaveLastReturnedWith(value: any): void;
lastReturnedWith(value: any): void;
/**
*
*/
toHaveNthReturnedWith(nthCall: number, value: any): void;
nthReturnedWith(nthCall: number, value: any): void;
/**
* Use .toHaveBeenCalledWith to ensure that a mock function was called with
* specific arguments.
*/
toHaveBeenCalledWith(...args: Array<any>): void,
toBeCalledWith(...args: Array<any>): void,
/**
* Use .toHaveBeenLastCalledWith to ensure that a mock function was last called
* with specific arguments.
*/
toHaveBeenLastCalledWith(...args: Array<any>): void,
lastCalledWith(...args: Array<any>): void,
/**
* Check that an object has a .length property and it is set to a certain
* numeric value.
@ -307,11 +698,22 @@ type JestExpectType = {
/**
* Use .toMatchObject to check that a javascript object matches a subset of the properties of an object.
*/
toMatchObject(object: Object): void,
toMatchObject(object: Object | Array<Object>): void,
/**
* This ensures that a React component matches the most recent snapshot.
* Use .toStrictEqual to check that a javascript object matches a subset of the properties of an object.
*/
toMatchSnapshot(name?: string): void,
toStrictEqual(value: any): void,
/**
* This ensures that an Object matches the most recent snapshot.
*/
toMatchSnapshot(propertyMatchers?: {[key: string]: JestAsymmetricEqualityType}, name?: string): void,
/**
* This ensures that an Object matches the most recent snapshot.
*/
toMatchSnapshot(name: string): void,
toMatchInlineSnapshot(snapshot?: string): void,
toMatchInlineSnapshot(propertyMatchers?: {[key: string]: JestAsymmetricEqualityType}, snapshot?: string): void,
/**
* Use .toThrow to test that a function throws when it is called.
* If you want to test that a specific error gets thrown, you can provide an
@ -320,14 +722,15 @@ type JestExpectType = {
*
* Alias: .toThrowError
*/
toThrow(message?: string | Error | RegExp): void,
toThrowError(message?: string | Error | RegExp): void,
toThrow(message?: string | Error | Class<Error> | RegExp): void,
toThrowError(message?: string | Error | Class<Error> | RegExp): void,
/**
* Use .toThrowErrorMatchingSnapshot to test that a function throws a error
* matching the most recent snapshot when it is called.
*/
toThrowErrorMatchingSnapshot(): void,
};
toThrowErrorMatchingInlineSnapshot(snapshot?: string): void,
}
type JestObjectType = {
/**
@ -382,7 +785,7 @@ type JestObjectType = {
* implementation.
*/
fn<TArguments: $ReadOnlyArray<*>, TReturn>(
implementation?: (...args: TArguments) => TReturn,
implementation?: (...args: TArguments) => TReturn
): JestMockFn<TArguments, TReturn>,
/**
* Determines if the given function is a mocked function.
@ -405,8 +808,18 @@ type JestObjectType = {
mock(
moduleName: string,
moduleFactory?: any,
options?: Object,
options?: Object
): JestObjectType,
/**
* Returns the actual module instead of a mock, bypassing all checks on
* whether the module should receive a mock implementation or not.
*/
requireActual(moduleName: string): any,
/**
* Returns a mock module instead of the actual module, bypassing all checks
* on whether the module should be required normally or not.
*/
requireMock(moduleName: string): any,
/**
* Resets the module registry - the cache of all required modules. This is
* useful to isolate modules where local state might conflict between tests.
@ -470,44 +883,37 @@ type JestObjectType = {
* Creates a mock function similar to jest.fn but also tracks calls to
* object[methodName].
*/
spyOn(object: Object, methodName: string): JestMockFn<any, any>,
spyOn(object: Object, methodName: string, accessType?: "get" | "set"): JestMockFn<any, any>,
/**
* Set the default timeout interval for tests and before/after hooks in milliseconds.
* Note: The default timeout interval is 5 seconds if this method is not called.
*/
setTimeout(timeout: number): JestObjectType,
// These methods are added separately and not a part of flow-typed OSS
// version of this file. They were added in jest@21.0.0.alpha-2 which is not
// yet publicly released yet.
// TODO T21262347 Add them to OSS version of flow-typed
requireActual(module: string): any,
requireMock(module: string): any,
setTimeout(timeout: number): JestObjectType
};
type JestSpyType = {
calls: JestCallsType,
calls: JestCallsType
};
/** Runs this function after every test inside this context */
declare function afterEach(
fn: (done: () => void) => ?Promise<mixed>,
timeout?: number,
timeout?: number
): void;
/** Runs this function before every test inside this context */
declare function beforeEach(
fn: (done: () => void) => ?Promise<mixed>,
timeout?: number,
timeout?: number
): void;
/** Runs this function after all tests have finished inside this context */
declare function afterAll(
fn: (done: () => void) => ?Promise<mixed>,
timeout?: number,
timeout?: number
): void;
/** Runs this function before any tests have started inside this context */
declare function beforeAll(
fn: (done: () => void) => ?Promise<mixed>,
timeout?: number,
timeout?: number
): void;
/** A context for grouping tests together */
@ -515,17 +921,29 @@ declare var describe: {
/**
* Creates a block that groups together several related tests in one "test suite"
*/
(name: string, fn: () => void): void,
(name: JestTestName, fn: () => void): void,
/**
* Only run this describe block
*/
only(name: string, fn: () => void): void,
only(name: JestTestName, fn: () => void): void,
/**
* Skip running this describe block
*/
skip(name: string, fn: () => void): void,
skip(name: JestTestName, fn: () => void): void,
/**
* each runs this test against array of argument arrays per each run
*
* @param {table} table of Test
*/
each(
table: Array<Array<mixed> | mixed>
): (
name: JestTestName,
fn?: (...args: Array<any>) => ?Promise<mixed>
) => void,
};
/** An individual test unit */
@ -533,56 +951,85 @@ declare var it: {
/**
* An individual test unit
*
* @param {string} Name of Test
* @param {JestTestName} Name of Test
* @param {Function} Test
* @param {number} Timeout for the test, in milliseconds.
*/
(
name: string,
name: JestTestName,
fn?: (done: () => void) => ?Promise<mixed>,
timeout?: number,
timeout?: number
): void,
/**
* each runs this test against array of argument arrays per each run
*
* @param {table} table of Test
*/
each(
table: Array<Array<mixed> | mixed>
): (
name: JestTestName,
fn?: (...args: Array<any>) => ?Promise<mixed>
) => void,
/**
* Only run this test
*
* @param {string} Name of Test
* @param {JestTestName} Name of Test
* @param {Function} Test
* @param {number} Timeout for the test, in milliseconds.
*/
only(
name: string,
name: JestTestName,
fn?: (done: () => void) => ?Promise<mixed>,
timeout?: number,
): void,
timeout?: number
): {
each(
table: Array<Array<mixed> | mixed>
): (
name: JestTestName,
fn?: (...args: Array<any>) => ?Promise<mixed>
) => void,
},
/**
* Skip running this test
*
* @param {string} Name of Test
* @param {JestTestName} Name of Test
* @param {Function} Test
* @param {number} Timeout for the test, in milliseconds.
*/
skip(
name: string,
name: JestTestName,
fn?: (done: () => void) => ?Promise<mixed>,
timeout?: number,
timeout?: number
): void,
/**
* Run the test concurrently
*
* @param {string} Name of Test
* @param {JestTestName} Name of Test
* @param {Function} Test
* @param {number} Timeout for the test, in milliseconds.
*/
concurrent(
name: string,
name: JestTestName,
fn?: (done: () => void) => ?Promise<mixed>,
timeout?: number,
timeout?: number
): void,
/**
* each runs this test against array of argument arrays per each run
*
* @param {table} table of Test
*/
each(
table: Array<Array<mixed> | mixed>
): (
name: JestTestName,
fn?: (...args: Array<any>) => ?Promise<mixed>
) => void,
};
declare function fit(
name: string,
name: JestTestName,
fn: (done: () => void) => ?Promise<mixed>,
timeout?: number,
timeout?: number
): void;
/** An individual test unit */
declare var test: typeof it;
@ -595,27 +1042,85 @@ declare var xit: typeof it;
/** A disabled individual test */
declare var xtest: typeof it;
type JestPrettyFormatColors = {
comment: { close: string, open: string },
content: { close: string, open: string },
prop: { close: string, open: string },
tag: { close: string, open: string },
value: { close: string, open: string },
};
type JestPrettyFormatIndent = string => string;
type JestPrettyFormatRefs = Array<any>;
type JestPrettyFormatPrint = any => string;
type JestPrettyFormatStringOrNull = string | null;
type JestPrettyFormatOptions = {|
callToJSON: boolean,
edgeSpacing: string,
escapeRegex: boolean,
highlight: boolean,
indent: number,
maxDepth: number,
min: boolean,
plugins: JestPrettyFormatPlugins,
printFunctionName: boolean,
spacing: string,
theme: {|
comment: string,
content: string,
prop: string,
tag: string,
value: string,
|},
|};
type JestPrettyFormatPlugin = {
print: (
val: any,
serialize: JestPrettyFormatPrint,
indent: JestPrettyFormatIndent,
opts: JestPrettyFormatOptions,
colors: JestPrettyFormatColors,
) => string,
test: any => boolean,
};
type JestPrettyFormatPlugins = Array<JestPrettyFormatPlugin>;
/** The expect function is used every time you want to test a value */
declare var expect: {
/** The object that you want to make assertions against */
(value: any): JestExpectType & JestPromiseType & EnzymeMatchersType,
(value: any):
& JestExpectType
& JestPromiseType
& EnzymeMatchersType
& DomTestingLibraryType
& JestJQueryMatchersType
& JestStyledComponentsMatchersType
& JestExtendedMatchersType,
/** Add additional Jasmine matchers to Jest's roster */
extend(matchers: {[name: string]: JestMatcher}): void,
extend(matchers: { [name: string]: JestMatcher }): void,
/** Add a module that formats application-specific data structures. */
addSnapshotSerializer(serializer: (input: Object) => string): void,
addSnapshotSerializer(pluginModule: JestPrettyFormatPlugin): void,
assertions(expectedAssertions: number): void,
hasAssertions(): void,
any(value: mixed): JestAsymmetricEqualityType,
anything(): void,
arrayContaining(value: Array<mixed>): void,
objectContaining(value: Object): void,
anything(): any,
arrayContaining(value: Array<mixed>): Array<mixed>,
objectContaining(value: Object): Object,
/** Matches any received string that contains the exact expected string. */
stringContaining(value: string): void,
stringMatching(value: string | RegExp): void,
stringContaining(value: string): string,
stringMatching(value: string | RegExp): string,
not: {
arrayContaining: (value: $ReadOnlyArray<mixed>) => Array<mixed>,
objectContaining: (value: {}) => Object,
stringContaining: (value: string) => string,
stringMatching: (value: string | RegExp) => string,
},
};
declare function fail(message?: string): void;
// TODO handle return type
// http://jasmine.github.io/2.4/introduction.html#section-Spies
declare function spyOn(value: mixed, method: string): Object;
@ -624,20 +1129,20 @@ declare function spyOn(value: mixed, method: string): Object;
declare var jest: JestObjectType;
/**
* The global Jamine object, this is generally not exposed as the public API,
* The global Jasmine object, this is generally not exposed as the public API,
* using features inside here could break in later versions of Jest.
*/
declare var jasmine: {
DEFAULT_TIMEOUT_INTERVAL: number,
any(value: mixed): JestAsymmetricEqualityType,
anything(): void,
arrayContaining(value: Array<mixed>): void,
anything(): any,
arrayContaining(value: Array<mixed>): Array<mixed>,
clock(): JestClockType,
createSpy(name: string): JestSpyType,
createSpyObj(
baseName: string,
methodNames: Array<string>,
): {[methodName: string]: JestSpyType},
objectContaining(value: Object): void,
stringMatching(value: string): void,
methodNames: Array<string>
): { [methodName: string]: JestSpyType },
objectContaining(value: Object): Object,
stringMatching(value: string): string
};