diff --git a/flow/jest.js b/flow/jest.js index 336c883836..6af3a65a60 100644 --- a/flow/jest.js +++ b/flow/jest.js @@ -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, TReturn> = { */ instances: Array, /** - * 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, TReturn> = { * will also be executed when the mock is called. */ mockImplementation( - fn: (...args: TArguments) => TReturn, + fn: (...args: TArguments) => TReturn ): JestMockFn, /** * Accepts a function that will be used as an implementation of the mock for @@ -81,48 +68,48 @@ type JestMockFn, TReturn> = { * calls produce different results. */ mockImplementationOnce( - fn: (...args: TArguments) => TReturn, + fn: (...args: TArguments) => TReturn ): JestMockFn, /** * 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, - /** - * Sugar for: jest.fn().mockReturnValue(Promise.reject(value)); - */ - mockRejectedValue(value: TReturn): JestMockFn, - /** - * Sugar for: jest.fn().mockReturnValueOnce(Promise.reject(value)); - */ - mockRejectedValueOnce(value: TReturn): JestMockFn, - /** - * Sugar for: jest.fn().mockReturnValue(Promise.resolve(value)); - */ - mockResolvedValue(value: TReturn): JestMockFn, - /** - * Sugar for: jest.fn().mockReturnValueOnce(Promise.resolve(value)); - */ - mockResolvedValueOnce(value: TReturn): JestMockFn, /** * 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, /** * Sugar for only returning a value once inside your mock */ mockReturnValueOnce(value: TReturn): JestMockFn, + /** + * Sugar for jest.fn().mockImplementation(() => Promise.resolve(value)) + */ + mockResolvedValue(value: TReturn): JestMockFn>, + /** + * Sugar for jest.fn().mockImplementationOnce(() => Promise.resolve(value)) + */ + mockResolvedValueOnce(value: TReturn): JestMockFn>, + /** + * Sugar for jest.fn().mockImplementation(() => Promise.reject(value)) + */ + mockRejectedValue(value: TReturn): JestMockFn>, + /** + * Sugar for jest.fn().mockImplementationOnce(() => Promise.reject(value)) + */ + mockRejectedValueOnce(value: TReturn): JestMockFn> }; 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; 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): 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): 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): 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.} keys + */ + toContainKeys(keys: string[]): void; + + /** + * Use `.toContainAllKeys` when checking if an object only contains all of the provided keys. + * + * @param {Array.} keys + */ + toContainAllKeys(keys: string[]): void; + + /** + * Use `.toContainAnyKeys` when checking if an object contains at least one of the provided keys. + * + * @param {Array.} 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.} entry + */ + toContainEntry(entry: [string, string]): void; + + /** + * Use `.toContainEntries` when checking if an object contains all of the provided entries. + * + * @param {Array.>} entries + */ + toContainEntries(entries: [string, string][]): void; + + /** + * Use `.toContainAllEntries` when checking if an object only contains all of the provided entries. + * + * @param {Array.>} entries + */ + toContainAllEntries(entries: [string, string][]): void; + + /** + * Use `.toContainAnyEntries` when checking if an object contains at least one of the provided entries. + * + * @param {Array.>} 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.} 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): void; + nthCalledWith(nthCall: number, ...args: Array): 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): void, + toBeCalledWith(...args: Array): void, /** * Use .toHaveBeenLastCalledWith to ensure that a mock function was last called * with specific arguments. */ toHaveBeenLastCalledWith(...args: Array): void, + lastCalledWith(...args: Array): 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): 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 | RegExp): void, + toThrowError(message?: string | Error | Class | 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, TReturn>( - implementation?: (...args: TArguments) => TReturn, + implementation?: (...args: TArguments) => TReturn ): JestMockFn, /** * 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, + spyOn(object: Object, methodName: string, accessType?: "get" | "set"): JestMockFn, /** * 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, - timeout?: number, + timeout?: number ): void; /** Runs this function before every test inside this context */ declare function beforeEach( fn: (done: () => void) => ?Promise, - timeout?: number, + timeout?: number ): void; /** Runs this function after all tests have finished inside this context */ declare function afterAll( fn: (done: () => void) => ?Promise, - timeout?: number, + timeout?: number ): void; /** Runs this function before any tests have started inside this context */ declare function beforeAll( fn: (done: () => void) => ?Promise, - 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 | mixed> + ): ( + name: JestTestName, + fn?: (...args: Array) => ?Promise + ) => 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, - 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 | mixed> + ): ( + name: JestTestName, + fn?: (...args: Array) => ?Promise + ) => 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, - timeout?: number, - ): void, + timeout?: number + ): { + each( + table: Array | mixed> + ): ( + name: JestTestName, + fn?: (...args: Array) => ?Promise + ) => 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, - 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, - 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 | mixed> + ): ( + name: JestTestName, + fn?: (...args: Array) => ?Promise + ) => void, }; declare function fit( - name: string, + name: JestTestName, fn: (done: () => void) => ?Promise, - 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; +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; + /** 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): void, - objectContaining(value: Object): void, + anything(): any, + arrayContaining(value: Array): Array, + 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) => Array, + 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): void, + anything(): any, + arrayContaining(value: Array): Array, clock(): JestClockType, createSpy(name: string): JestSpyType, createSpyObj( baseName: string, - methodNames: Array, - ): {[methodName: string]: JestSpyType}, - objectContaining(value: Object): void, - stringMatching(value: string): void, + methodNames: Array + ): { [methodName: string]: JestSpyType }, + objectContaining(value: Object): Object, + stringMatching(value: string): string };