diff --git a/flow-typed/npm/jest_v23.x.x.js b/flow-typed/npm/jest_v26.x.x.js similarity index 59% rename from flow-typed/npm/jest_v23.x.x.js rename to flow-typed/npm/jest_v26.x.x.js index dbfc9b687..bb0a086df 100644 --- a/flow-typed/npm/jest_v23.x.x.js +++ b/flow-typed/npm/jest_v26.x.x.js @@ -1,5 +1,5 @@ -// flow-typed signature: 691597c4a5aab83a3b2e6d9ccd01a97d -// flow-typed version: 71534a866d/jest_v23.x.x/flow_>=v0.39.x +// flow-typed signature: 9a1f9054d272cf6383233b8bfb639f84 +// flow-typed version: 4efeddffd8/jest_v26.x.x/flow_>=v0.104.x type JestMockFn, TReturn> = { (...args: TArguments): TReturn, @@ -22,7 +22,12 @@ type JestMockFn, TReturn> = { * An array that contains all the object results that have been * returned by this mock function call */ - results: Array<{ isThrow: boolean, value: TReturn }> + results: Array<{ + isThrow: boolean, + value: TReturn, + ... + }>, + ... }, /** * Resets all information stored in the mockFn.mock.calls and @@ -84,7 +89,9 @@ type JestMockFn, TReturn> = { /** * Sugar for jest.fn().mockImplementationOnce(() => Promise.resolve(value)) */ - mockResolvedValueOnce(value: TReturn): JestMockFn>, + mockResolvedValueOnce( + value: TReturn + ): JestMockFn>, /** * Sugar for jest.fn().mockImplementation(() => Promise.reject(value)) */ @@ -92,14 +99,16 @@ type JestMockFn, TReturn> = { /** * Sugar for jest.fn().mockImplementationOnce(() => Promise.reject(value)) */ - mockRejectedValueOnce(value: TReturn): JestMockFn> + mockRejectedValueOnce(value: TReturn): JestMockFn>, + ... }; type JestAsymmetricEqualityType = { /** * A custom Jasmine equality tester */ - asymmetricMatch(value: mixed): boolean + asymmetricMatch(value: mixed): boolean, + ... }; type JestCallsType = { @@ -109,24 +118,28 @@ 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 - | Promise; +type JestMatcher = ( + received: any, + ...actual: Array +) => JestMatcherResult | Promise; type JestPromiseType = { /** @@ -138,7 +151,8 @@ 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, + ... }; /** @@ -158,10 +172,11 @@ type JestStyledComponentsMatcherValue = | typeof undefined; type JestStyledComponentsMatcherOptions = { - media?: string; - modifier?: string; - supports?: string; -} + media?: string, + modifier?: string, + supports?: string, + ... +}; type JestStyledComponentsMatchersType = { toHaveStyleRule( @@ -169,6 +184,7 @@ type JestStyledComponentsMatchersType = { value: JestStyledComponentsMatcherValue, options?: JestStyledComponentsMatcherOptions ): void, + ... }; /** @@ -182,33 +198,68 @@ type EnzymeMatchersType = { toBeChecked(): void, toBeDisabled(): void, toBeEmptyRender(): void, - toContainMatchingElement(selector: string): void; - toContainMatchingElements(n: number, selector: string): void; - toContainExactlyOneMatchingElement(selector: string): void; + toContainMatchingElement(selector: string): void, + toContainMatchingElements(n: number, selector: string): void, + toContainExactlyOneMatchingElement(selector: string): void, toContainReact(element: React$Element): void, toExist(): void, toHaveClassName(className: string): void, toHaveHTML(html: string): void, - toHaveProp: ((propKey: string, propValue?: any) => void) & ((props: Object) => void), + toHaveProp: ((propKey: string, propValue?: any) => void) & + ((props: { ... }) => void), toHaveRef(refName: string): void, - toHaveState: ((stateKey: string, stateValue?: any) => void) & ((state: Object) => void), - toHaveStyle: ((styleKey: string, styleValue?: any) => void) & ((style: Object) => void), + toHaveState: ((stateKey: string, stateValue?: any) => void) & + ((state: { ... }) => void), + toHaveStyle: ((styleKey: string, styleValue?: any) => void) & + ((style: { ... }) => void), toHaveTagName(tagName: string): void, toHaveText(text: string): void, toHaveValue(value: any): void, toIncludeText(text: string): void, toMatchElement( element: React$Element, - options?: {| ignoreProps?: boolean |}, + options?: {| ignoreProps?: boolean, verbose?: boolean |} ): void, - toMatchSelector(selector: string): void + toMatchSelector(selector: string): void, + // 7.x + toHaveDisplayName(name: string): void, + ... }; -// DOM testing library extensions https://github.com/kentcdodds/dom-testing-library#custom-jest-matchers +// DOM testing library extensions (jest-dom) +// https://github.com/testing-library/jest-dom type DomTestingLibraryType = { - toBeInTheDOM(): void, - toHaveTextContent(content: string): void, - toHaveAttribute(name: string, expectedValue?: string): void + /** + * @deprecated + */ + toBeInTheDOM(container?: HTMLElement): void, + + // 4.x + toBeInTheDocument(): void, + toBeVisible(): void, + toBeEmpty(): void, + toBeDisabled(): void, + toBeEnabled(): void, + toBeInvalid(): void, + toBeRequired(): void, + toBeValid(): void, + toContainElement(element: HTMLElement | null): void, + toContainHTML(htmlText: string): void, + toHaveAttribute(attr: string, value?: any): void, + toHaveClass(...classNames: string[]): void, + toHaveFocus(): void, + toHaveFormValues(expectedValues: { [name: string]: any, ... }): void, + toHaveStyle(css: string | { [name: string]: any, ... }): void, + toHaveTextContent( + text: string | RegExp, + options?: {| normalizeWhitespace: boolean |} + ): void, + toHaveValue(value?: string | string[] | number): void, + + // 5.x + toHaveDisplayValue(value: string | string[]): void, + toBeChecked(): void, + ... }; // Jest JQuery Matchers: https://github.com/unindented/custom-jquery-matchers @@ -223,7 +274,7 @@ type JestJQueryMatchersType = { toHaveText(text: string | RegExp): void, toHaveData(key: string, val?: any): void, toHaveValue(val: any): void, - toHaveCss(css: {[key: string]: any}): void, + toHaveCss(css: { [key: string]: any, ... }): void, toBeChecked(): void, toBeDisabled(): void, toBeEmpty(): void, @@ -234,409 +285,387 @@ type JestJQueryMatchersType = { toBeInDom(): void, toBeMatchedBy(sel: string): void, toHaveDescendant(sel: string): void, - toHaveDescendantWithText(sel: string, text: string | RegExp): 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 - */ + * Note: Currently unimplemented + * Passing assertion + * + * @param {String} message + */ // pass(message: string): void; - /** - * Note: Currently unimplemented - * Failing assertion - * - * @param {String} message - */ + /** + * 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 .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, + ... +}; - /** - * Use `.toIncludeMultiple` when checking if a `String` includes all of the given substrings. - * - * @param {Array.} substring - */ - toIncludeMultiple(substring: string[]): void; +// Diffing snapshot utility for Jest (snapshot-diff) +// https://github.com/jest-community/snapshot-diff +type SnapshotDiffType = { + /** + * Compare the difference between the actual in the `expect()` + * vs the object inside `valueB` with some extra options. + */ + toMatchDiffSnapshot( + valueB: any, + options?: {| + expand?: boolean, + colors?: boolean, + contextLines?: number, + stablePatchmarks?: boolean, + aAnnotation?: string, + bAnnotation?: string, + |}, + testName?: string + ): void, + ... }; interface JestExpectType { - not: - & JestExpectType - & EnzymeMatchersType - & DomTestingLibraryType - & JestJQueryMatchersType - & JestStyledComponentsMatchersType - & JestExtendedMatchersType, + not: JestExpectType & + EnzymeMatchersType & + DomTestingLibraryType & + JestJQueryMatchersType & + JestStyledComponentsMatchersType & + JestExtendedMatchersType & + SnapshotDiffType; /** * If you have a mock function, you can use .lastCalledWith to test what * arguments it was last called with. */ - lastCalledWith(...args: Array): void, + lastCalledWith(...args: Array): void; /** * toBe just checks that a value is what you expect. It uses === to check * strict equality. */ - toBe(value: any): void, + toBe(value: any): void; /** * Use .toBeCalledWith to ensure that a mock function was called with * specific arguments. */ - toBeCalledWith(...args: Array): void, + toBeCalledWith(...args: Array): void; /** * Using exact equality with floating point numbers is a bad idea. Rounding * means that intuitive things fail. */ - toBeCloseTo(num: number, delta: any): void, + toBeCloseTo(num: number, delta: any): void; /** * Use .toBeDefined to check that a variable is not undefined. */ - toBeDefined(): void, + toBeDefined(): void; /** * Use .toBeFalsy when you don't care what a value is, you just want to * ensure a value is false in a boolean context. */ - toBeFalsy(): void, + toBeFalsy(): void; /** * To compare floating point numbers, you can use toBeGreaterThan. */ - toBeGreaterThan(number: number): void, + toBeGreaterThan(number: number): void; /** * To compare floating point numbers, you can use toBeGreaterThanOrEqual. */ - toBeGreaterThanOrEqual(number: number): void, + toBeGreaterThanOrEqual(number: number): void; /** * To compare floating point numbers, you can use toBeLessThan. */ - toBeLessThan(number: number): void, + toBeLessThan(number: number): void; /** * To compare floating point numbers, you can use toBeLessThanOrEqual. */ - toBeLessThanOrEqual(number: number): void, + toBeLessThanOrEqual(number: number): void; /** * Use .toBeInstanceOf(Class) to check that an object is an instance of a * class. */ - toBeInstanceOf(cls: Class<*>): void, + toBeInstanceOf(cls: Class<*>): void; /** * .toBeNull() is the same as .toBe(null) but the error messages are a bit * nicer. */ - toBeNull(): void, + toBeNull(): void; /** * Use .toBeTruthy when you don't care what a value is, you just want to * ensure a value is true in a boolean context. */ - toBeTruthy(): void, + toBeTruthy(): void; /** * Use .toBeUndefined to check that a variable is undefined. */ - toBeUndefined(): void, + toBeUndefined(): void; /** * Use .toContain when you want to check that an item is in a list. For * testing the items in the list, this uses ===, a strict equality check. */ - toContain(item: any): void, + toContain(item: any): void; /** * Use .toContainEqual when you want to check that an item is in a list. For * testing the items in the list, this matcher recursively checks the * equality of all fields, rather than checking for object identity. */ - toContainEqual(item: any): void, + toContainEqual(item: any): void; /** * Use .toEqual when you want to check that two objects have the same value. * This matcher recursively checks the equality of all fields, rather than * checking for object identity. */ - toEqual(value: any): void, + toEqual(value: any): void; /** * Use .toHaveBeenCalled to ensure that a mock function got called. */ - toHaveBeenCalled(): void, + toHaveBeenCalled(): void; toBeCalled(): void; /** * Use .toHaveBeenCalledTimes to ensure that a mock function got called exact * number of times. */ - toHaveBeenCalledTimes(number: number): void, + toHaveBeenCalledTimes(number: number): void; toBeCalledTimes(number: number): void; /** * @@ -672,46 +701,46 @@ interface JestExpectType { * Use .toHaveBeenCalledWith to ensure that a mock function was called with * specific arguments. */ - toHaveBeenCalledWith(...args: Array): void, - toBeCalledWith(...args: Array): void, + 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, + 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. */ - toHaveLength(number: number): void, + toHaveLength(number: number): void; /** * */ - toHaveProperty(propPath: string, value?: any): void, + toHaveProperty(propPath: string | $ReadOnlyArray, value?: any): void; /** * Use .toMatch to check that a string matches a regular expression or string. */ - toMatch(regexpOrString: RegExp | string): void, + toMatch(regexpOrString: RegExp | string): void; /** * Use .toMatchObject to check that a javascript object matches a subset of the properties of an object. */ - toMatchObject(object: Object | Array): void, + toMatchObject(object: Object | Array): void; /** * Use .toStrictEqual to check that a javascript object matches a subset of the properties of an object. */ - toStrictEqual(value: any): void, + toStrictEqual(value: any): void; /** * This ensures that an Object matches the most recent snapshot. */ - toMatchSnapshot(propertyMatchers?: any, name?: string): void, + toMatchSnapshot(propertyMatchers?: any, name?: string): void; /** * This ensures that an Object matches the most recent snapshot. */ - toMatchSnapshot(name: string): void, + toMatchSnapshot(name: string): void; - toMatchInlineSnapshot(snapshot?: string): void, - toMatchInlineSnapshot(propertyMatchers?: any, snapshot?: string): void, + toMatchInlineSnapshot(snapshot?: string): void; + toMatchInlineSnapshot(propertyMatchers?: any, 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 @@ -720,14 +749,14 @@ interface JestExpectType { * * Alias: .toThrowError */ - toThrow(message?: string | Error | Class | RegExp): void, - toThrowError(message?: string | Error | Class | 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, + toThrowErrorMatchingSnapshot(): void; + toThrowErrorMatchingInlineSnapshot(snapshot?: string): void; } type JestObjectType = { @@ -768,6 +797,10 @@ type JestObjectType = { * Removes any pending timers from the timer system. */ clearAllTimers(): void, + /** + * Returns the number of fake timers still left to run. + */ + getTimerCount(): number, /** * The same as `mock` but not moved to the top of the expectation by * babel-jest. @@ -823,6 +856,12 @@ type JestObjectType = { * useful to isolate modules where local state might conflict between tests. */ resetModules(): JestObjectType, + /** + * Creates a sandbox registry for the modules that are loaded inside the + * callback function. This is useful to isolate specific modules for every + * test so that local module state doesn't conflict between tests. + */ + isolateModules(fn: () => void): JestObjectType, /** * Exhausts the micro-task queue (usually interfaced in node via * process.nextTick). @@ -872,7 +911,7 @@ type JestObjectType = { * (setTimeout, setInterval, clearTimeout, clearInterval, nextTick, * setImmediate and clearImmediate). */ - useFakeTimers(): JestObjectType, + useFakeTimers(mode?: 'modern' | 'legacy'): JestObjectType, /** * Instructs Jest to use the real versions of the standard timer functions. */ @@ -881,36 +920,44 @@ type JestObjectType = { * Creates a mock function similar to jest.fn but also tracks calls to * object[methodName]. */ - spyOn(object: Object, methodName: string, accessType?: "get" | "set"): 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 + setTimeout(timeout: number): JestObjectType, + ... }; -type JestSpyType = { - calls: JestCallsType -}; +type JestSpyType = { calls: JestCallsType, ... }; + +type JestDoneFn = {| + (error?: Error): void, + fail: (error: Error) => void, +|}; /** Runs this function after every test inside this context */ declare function afterEach( - fn: (done: () => void) => ?Promise, + fn: (done: JestDoneFn) => ?Promise, timeout?: number ): void; /** Runs this function before every test inside this context */ declare function beforeEach( - fn: (done: () => void) => ?Promise, + fn: (done: JestDoneFn) => ?Promise, timeout?: number ): void; /** Runs this function after all tests have finished inside this context */ declare function afterAll( - fn: (done: () => void) => ?Promise, + fn: (done: JestDoneFn) => ?Promise, timeout?: number ): void; /** Runs this function before any tests have started inside this context */ declare function beforeAll( - fn: (done: () => void) => ?Promise, + fn: (done: JestDoneFn) => ?Promise, timeout?: number ): void; @@ -920,28 +967,27 @@ declare var describe: { * Creates a block that groups together several related tests in one "test suite" */ (name: JestTestName, fn: () => void): void, - /** * Only run this describe block */ only(name: JestTestName, fn: () => void): void, - /** * Skip running this describe block */ 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> + ...table: Array | mixed> | [Array, string] ): ( name: JestTestName, - fn?: (...args: Array) => ?Promise + fn?: (...args: Array) => ?Promise, + timeout?: number ) => void, + ... }; /** An individual test unit */ @@ -955,20 +1001,9 @@ declare var it: { */ ( name: JestTestName, - fn?: (done: () => void) => ?Promise, + fn?: (done: JestDoneFn) => ?Promise, 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 * @@ -976,18 +1011,20 @@ declare var it: { * @param {Function} Test * @param {number} Timeout for the test, in milliseconds. */ - only( - name: JestTestName, - fn?: (done: () => void) => ?Promise, - timeout?: number - ): { + only: {| + ( + name: JestTestName, + fn?: (done: JestDoneFn) => ?Promise, + timeout?: number + ): void, each( - table: Array | mixed> + ...table: Array | mixed> | [Array, string] ): ( name: JestTestName, - fn?: (...args: Array) => ?Promise + fn?: (...args: Array) => ?Promise, + timeout?: number ) => void, - }, + |}, /** * Skip running this test * @@ -997,9 +1034,15 @@ declare var it: { */ skip( name: JestTestName, - fn?: (done: () => void) => ?Promise, + fn?: (done: JestDoneFn) => ?Promise, timeout?: number ): void, + /** + * Highlight planned tests in the summary output + * + * @param {String} Name of Test to do + */ + todo(name: string): void, /** * Run the test concurrently * @@ -1009,7 +1052,7 @@ declare var it: { */ concurrent( name: JestTestName, - fn?: (done: () => void) => ?Promise, + fn?: (done: JestDoneFn) => ?Promise, timeout?: number ): void, /** @@ -1018,15 +1061,18 @@ declare var it: { * @param {table} table of Test */ each( - table: Array | mixed> + ...table: Array | mixed> | [Array, string] ): ( name: JestTestName, - fn?: (...args: Array) => ?Promise + fn?: (...args: Array) => ?Promise, + timeout?: number ) => void, + ... }; + declare function fit( name: JestTestName, - fn: (done: () => void) => ?Promise, + fn: (done: JestDoneFn) => ?Promise, timeout?: number ): void; /** An individual test unit */ @@ -1041,16 +1087,37 @@ declare var xit: typeof it; 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 }, + 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 JestPrettyFormatIndent = (string) => string; type JestPrettyFormatRefs = Array; -type JestPrettyFormatPrint = any => string; +type JestPrettyFormatPrint = (any) => string; type JestPrettyFormatStringOrNull = string | null; type JestPrettyFormatOptions = {| @@ -1079,9 +1146,10 @@ type JestPrettyFormatPlugin = { serialize: JestPrettyFormatPrint, indent: JestPrettyFormatIndent, opts: JestPrettyFormatOptions, - colors: JestPrettyFormatColors, + colors: JestPrettyFormatColors ) => string, - test: any => boolean, + test: (any) => boolean, + ... }; type JestPrettyFormatPlugins = Array; @@ -1089,17 +1157,18 @@ 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 - & DomTestingLibraryType - & JestJQueryMatchersType - & JestStyledComponentsMatchersType - & JestExtendedMatchersType, - + ( + value: any + ): JestExpectType & + JestPromiseType & + EnzymeMatchersType & + DomTestingLibraryType & + JestJQueryMatchersType & + JestStyledComponentsMatchersType & + JestExtendedMatchersType & + SnapshotDiffType, /** 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(pluginModule: JestPrettyFormatPlugin): void, assertions(expectedAssertions: number): void, @@ -1113,10 +1182,12 @@ declare var expect: { stringMatching(value: string | RegExp): string, not: { arrayContaining: (value: $ReadOnlyArray) => Array, - objectContaining: (value: {}) => Object, + objectContaining: (value: { ... }) => Object, stringContaining: (value: string) => string, stringMatching: (value: string | RegExp) => string, + ... }, + ... }; // TODO handle return type @@ -1140,7 +1211,8 @@ declare var jasmine: { createSpyObj( baseName: string, methodNames: Array - ): { [methodName: string]: JestSpyType }, + ): { [methodName: string]: JestSpyType, ... }, objectContaining(value: Object): Object, - stringMatching(value: string): string + stringMatching(value: string): string, + ... }; diff --git a/src/__tests__/jest-native.test.js b/src/__tests__/jest-native.test.js index 741d8d1b8..c64226af3 100644 --- a/src/__tests__/jest-native.test.js +++ b/src/__tests__/jest-native.test.js @@ -36,12 +36,8 @@ test('jest-native matchers work correctly', () => { ); - // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings expect(getByText('Enabled Button')).toBeEnabled(); - - // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings expect(getByText('Disabled Button')).not.toBeEnabled(); - expect(getByText('Disabled Button')).toBeDisabled(); expect(getByText('Enabled Button')).not.toBeDisabled(); @@ -50,21 +46,20 @@ test('jest-native matchers work correctly', () => { expect(getByA11yHint('Not Empty Text')).not.toBeEmpty(); expect(getByA11yHint('Not Empty View')).not.toBeEmpty(); - // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings expect(getByA11yHint('Container View')).toContainElement( + // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings getByA11yHint('First-Level Child') ); - // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings expect(getByA11yHint('Container View')).toContainElement( + // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings getByText('Second-Level Child') ); - // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings expect(getByA11yHint('Container View')).not.toContainElement( + // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings getByText('Enabled Button') ); expect(getByA11yHint('Not Empty Text')).toHaveTextContent('Not empty'); - // $FlowFixMe - TODO: fix @testing-library/jest-native flow typings expect(getByA11yHint('Not Empty Text')).toHaveTextContent(/Not empty/); expect(getByA11yHint('Not Empty Text')).not.toHaveTextContent('Is empty');