1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. 'use strict';
    
  11. 
    
  12. /* eslint-disable no-unused-vars */
    
  13. 
    
  14. type JestMockFn<TArguments: $ReadOnlyArray<any>, TReturn> = {
    
  15.   (...args: TArguments): TReturn,
    
  16.   /**
    
  17.    * An object for introspecting mock calls
    
  18.    */
    
  19.   mock: {
    
  20.     /**
    
  21.      * An array that represents all calls that have been made into this mock
    
  22.      * function. Each call is represented by an array of arguments that were
    
  23.      * passed during the call.
    
  24.      */
    
  25.     calls: Array<TArguments>,
    
  26.     /**
    
  27.      * An array that contains all the object instances that have been
    
  28.      * instantiated from this mock function.
    
  29.      */
    
  30.     instances: Array<TReturn>,
    
  31.     /**
    
  32.      * An array that contains all the object results that have been
    
  33.      * returned by this mock function call
    
  34.      */
    
  35.     results: Array<{isThrow: boolean, value: TReturn}>,
    
  36.   },
    
  37.   /**
    
  38.    * Resets all information stored in the mockFn.mock.calls and
    
  39.    * mockFn.mock.instances arrays. Often this is useful when you want to clean
    
  40.    * up a mock's usage data between two assertions.
    
  41.    */
    
  42.   mockClear(): void,
    
  43.   /**
    
  44.    * Resets all information stored in the mock. This is useful when you want to
    
  45.    * completely restore a mock back to its initial state.
    
  46.    */
    
  47.   mockReset(): void,
    
  48.   /**
    
  49.    * Removes the mock and restores the initial implementation. This is useful
    
  50.    * when you want to mock functions in certain test cases and restore the
    
  51.    * original implementation in others. Beware that mockFn.mockRestore only
    
  52.    * works when mock was created with jest.spyOn. Thus you have to take care of
    
  53.    * restoration yourself when manually assigning jest.fn().
    
  54.    */
    
  55.   mockRestore(): void,
    
  56.   /**
    
  57.    * Accepts a function that should be used as the implementation of the mock.
    
  58.    * The mock itself will still record all calls that go into and instances
    
  59.    * that come from itself -- the only difference is that the implementation
    
  60.    * will also be executed when the mock is called.
    
  61.    */
    
  62.   mockImplementation(
    
  63.     fn: (...args: TArguments) => TReturn
    
  64.   ): JestMockFn<TArguments, TReturn>,
    
  65.   /**
    
  66.    * Accepts a function that will be used as an implementation of the mock for
    
  67.    * one call to the mocked function. Can be chained so that multiple function
    
  68.    * calls produce different results.
    
  69.    */
    
  70.   mockImplementationOnce(
    
  71.     fn: (...args: TArguments) => TReturn
    
  72.   ): JestMockFn<TArguments, TReturn>,
    
  73.   /**
    
  74.    * Accepts a string to use in test result output in place of "jest.fn()" to
    
  75.    * indicate which mock function is being referenced.
    
  76.    */
    
  77.   mockName(name: string): JestMockFn<TArguments, TReturn>,
    
  78.   /**
    
  79.    * Just a simple sugar function for returning `this`
    
  80.    */
    
  81.   mockReturnThis(): void,
    
  82.   /**
    
  83.    * Accepts a value that will be returned whenever the mock function is called.
    
  84.    */
    
  85.   mockReturnValue(value: TReturn): JestMockFn<TArguments, TReturn>,
    
  86.   /**
    
  87.    * Sugar for only returning a value once inside your mock
    
  88.    */
    
  89.   mockReturnValueOnce(value: TReturn): JestMockFn<TArguments, TReturn>,
    
  90.   /**
    
  91.    * Sugar for jest.fn().mockImplementation(() => Promise.resolve(value))
    
  92.    */
    
  93.   mockResolvedValue(value: TReturn): JestMockFn<TArguments, Promise<TReturn>>,
    
  94.   /**
    
  95.    * Sugar for jest.fn().mockImplementationOnce(() => Promise.resolve(value))
    
  96.    */
    
  97.   mockResolvedValueOnce(
    
  98.     value: TReturn
    
  99.   ): JestMockFn<TArguments, Promise<TReturn>>,
    
  100.   /**
    
  101.    * Sugar for jest.fn().mockImplementation(() => Promise.reject(value))
    
  102.    */
    
  103.   mockRejectedValue(value: TReturn): JestMockFn<TArguments, Promise<any>>,
    
  104.   /**
    
  105.    * Sugar for jest.fn().mockImplementationOnce(() => Promise.reject(value))
    
  106.    */
    
  107.   mockRejectedValueOnce(value: TReturn): JestMockFn<TArguments, Promise<any>>,
    
  108. };
    
  109. 
    
  110. type JestAsymmetricEqualityType = {
    
  111.   /**
    
  112.    * A custom Jasmine equality tester
    
  113.    */
    
  114.   asymmetricMatch(value: mixed): boolean,
    
  115. };
    
  116. 
    
  117. type JestCallsType = {
    
  118.   allArgs(): mixed,
    
  119.   all(): mixed,
    
  120.   any(): boolean,
    
  121.   count(): number,
    
  122.   first(): mixed,
    
  123.   mostRecent(): mixed,
    
  124.   reset(): void,
    
  125. };
    
  126. 
    
  127. type JestClockType = {
    
  128.   install(): void,
    
  129.   mockDate(date: Date): void,
    
  130.   tick(milliseconds?: number): void,
    
  131.   uninstall(): void,
    
  132. };
    
  133. 
    
  134. type JestMatcherResult = {
    
  135.   message?: string | (() => string),
    
  136.   pass: boolean,
    
  137. };
    
  138. 
    
  139. type JestMatcher = (
    
  140.   actual: any,
    
  141.   expected: any
    
  142. ) => JestMatcherResult | Promise<JestMatcherResult>;
    
  143. 
    
  144. type JestPromiseType = {
    
  145.   /**
    
  146.    * Use rejects to unwrap the reason of a rejected promise so any other
    
  147.    * matcher can be chained. If the promise is fulfilled the assertion fails.
    
  148.    */
    
  149.   // eslint-disable-next-line no-use-before-define
    
  150.   rejects: JestExpectType,
    
  151.   /**
    
  152.    * Use resolves to unwrap the value of a fulfilled promise so any other
    
  153.    * matcher can be chained. If the promise is rejected the assertion fails.
    
  154.    */
    
  155.   // eslint-disable-next-line no-use-before-define
    
  156.   resolves: JestExpectType,
    
  157. };
    
  158. 
    
  159. /**
    
  160.  * Jest allows functions and classes to be used as test names in test() and
    
  161.  * describe()
    
  162.  */
    
  163. type JestTestName = string | Function;
    
  164. 
    
  165. /**
    
  166.  *  Plugin: jest-styled-components
    
  167.  */
    
  168. 
    
  169. type JestStyledComponentsMatcherValue =
    
  170.   | string
    
  171.   | JestAsymmetricEqualityType
    
  172.   | RegExp
    
  173.   | typeof undefined;
    
  174. 
    
  175. type JestStyledComponentsMatcherOptions = {
    
  176.   media?: string,
    
  177.   modifier?: string,
    
  178.   supports?: string,
    
  179. };
    
  180. 
    
  181. type JestStyledComponentsMatchersType = {
    
  182.   toHaveStyleRule(
    
  183.     property: string,
    
  184.     value: JestStyledComponentsMatcherValue,
    
  185.     options?: JestStyledComponentsMatcherOptions
    
  186.   ): void,
    
  187. };
    
  188. 
    
  189. /**
    
  190.  *  Plugin: jest-enzyme
    
  191.  */
    
  192. type EnzymeMatchersType = {
    
  193.   // 5.x
    
  194.   toBeEmpty(): void,
    
  195.   toBePresent(): void,
    
  196.   // 6.x
    
  197.   toBeChecked(): void,
    
  198.   toBeDisabled(): void,
    
  199.   toBeEmptyRender(): void,
    
  200.   toContainMatchingElement(selector: string): void,
    
  201.   toContainMatchingElements(n: number, selector: string): void,
    
  202.   toContainExactlyOneMatchingElement(selector: string): void,
    
  203.   toContainReact(element: React$Element<any>): void,
    
  204.   toExist(): void,
    
  205.   toHaveClassName(className: string): void,
    
  206.   toHaveHTML(html: string): void,
    
  207.   toHaveProp: ((propKey: string, propValue?: any) => void) &
    
  208.     ((props: {}) => void),
    
  209.   toHaveRef(refName: string): void,
    
  210.   toHaveState: ((stateKey: string, stateValue?: any) => void) &
    
  211.     ((state: {}) => void),
    
  212.   toHaveStyle: ((styleKey: string, styleValue?: any) => void) &
    
  213.     ((style: {}) => void),
    
  214.   toHaveTagName(tagName: string): void,
    
  215.   toHaveText(text: string): void,
    
  216.   toHaveValue(value: any): void,
    
  217.   toIncludeText(text: string): void,
    
  218.   toMatchElement(
    
  219.     element: React$Element<any>,
    
  220.     options?: {ignoreProps?: boolean, verbose?: boolean}
    
  221.   ): void,
    
  222.   toMatchSelector(selector: string): void,
    
  223.   // 7.x
    
  224.   toHaveDisplayName(name: string): void,
    
  225. };
    
  226. 
    
  227. // DOM testing library extensions https://github.com/kentcdodds/dom-testing-library#custom-jest-matchers
    
  228. type DomTestingLibraryType = {
    
  229.   toBeDisabled(): void,
    
  230.   toBeEmpty(): void,
    
  231.   toBeInTheDocument(): void,
    
  232.   toBeVisible(): void,
    
  233.   toContainElement(element: HTMLElement | null): void,
    
  234.   toContainHTML(htmlText: string): void,
    
  235.   toHaveAttribute(name: string, expectedValue?: string): void,
    
  236.   toHaveClass(...classNames: string[]): void,
    
  237.   toHaveFocus(): void,
    
  238.   toHaveFormValues(expectedValues: {[name: string]: any}): void,
    
  239.   toHaveStyle(css: string): void,
    
  240.   toHaveTextContent(
    
  241.     content: string | RegExp,
    
  242.     options?: {normalizeWhitespace: boolean}
    
  243.   ): void,
    
  244.   toBeInTheDOM(): void,
    
  245. };
    
  246. 
    
  247. // Jest JQuery Matchers: https://github.com/unindented/custom-jquery-matchers
    
  248. type JestJQueryMatchersType = {
    
  249.   toExist(): void,
    
  250.   toHaveLength(len: number): void,
    
  251.   toHaveId(id: string): void,
    
  252.   toHaveClass(className: string): void,
    
  253.   toHaveTag(tag: string): void,
    
  254.   toHaveAttr(key: string, val?: any): void,
    
  255.   toHaveProp(key: string, val?: any): void,
    
  256.   toHaveText(text: string | RegExp): void,
    
  257.   toHaveData(key: string, val?: any): void,
    
  258.   toHaveValue(val: any): void,
    
  259.   toHaveCss(css: {[key: string]: any}): void,
    
  260.   toBeChecked(): void,
    
  261.   toBeDisabled(): void,
    
  262.   toBeEmpty(): void,
    
  263.   toBeHidden(): void,
    
  264.   toBeSelected(): void,
    
  265.   toBeVisible(): void,
    
  266.   toBeFocused(): void,
    
  267.   toBeInDom(): void,
    
  268.   toBeMatchedBy(sel: string): void,
    
  269.   toHaveDescendant(sel: string): void,
    
  270.   toHaveDescendantWithText(sel: string, text: string | RegExp): void,
    
  271. };
    
  272. 
    
  273. // Jest Extended Matchers: https://github.com/jest-community/jest-extended
    
  274. type JestExtendedMatchersType = {
    
  275.   /**
    
  276.    * Note: Currently unimplemented
    
  277.    * Passing assertion
    
  278.    *
    
  279.    * @param {String} message
    
  280.    */
    
  281.   //  pass(message: string): void;
    
  282. 
    
  283.   /**
    
  284.    * Note: Currently unimplemented
    
  285.    * Failing assertion
    
  286.    *
    
  287.    * @param {String} message
    
  288.    */
    
  289.   //  fail(message: string): void;
    
  290. 
    
  291.   /**
    
  292.    * Use .toBeEmpty when checking if a String '', Array [] or Object {} is empty.
    
  293.    */
    
  294.   toBeEmpty(): void,
    
  295. 
    
  296.   /**
    
  297.    * Use .toBeOneOf when checking if a value is a member of a given Array.
    
  298.    * @param {Array.<*>} members
    
  299.    */
    
  300.   toBeOneOf(members: any[]): void,
    
  301. 
    
  302.   /**
    
  303.    * Use `.toBeNil` when checking a value is `null` or `undefined`.
    
  304.    */
    
  305.   toBeNil(): void,
    
  306. 
    
  307.   /**
    
  308.    * Use `.toSatisfy` when you want to use a custom matcher by supplying a predicate function that returns a `Boolean`.
    
  309.    * @param {Function} predicate
    
  310.    */
    
  311.   toSatisfy(predicate: (n: any) => boolean): void,
    
  312. 
    
  313.   /**
    
  314.    * Use `.toBeArray` when checking if a value is an `Array`.
    
  315.    */
    
  316.   toBeArray(): void,
    
  317. 
    
  318.   /**
    
  319.    * Use `.toBeArrayOfSize` when checking if a value is an `Array` of size x.
    
  320.    * @param {Number} x
    
  321.    */
    
  322.   toBeArrayOfSize(x: number): void,
    
  323. 
    
  324.   /**
    
  325.    * Use `.toIncludeAllMembers` when checking if an `Array` contains all of the same members of a given set.
    
  326.    * @param {Array.<*>} members
    
  327.    */
    
  328.   toIncludeAllMembers(members: any[]): void,
    
  329. 
    
  330.   /**
    
  331.    * Use `.toIncludeAnyMembers` when checking if an `Array` contains any of the members of a given set.
    
  332.    * @param {Array.<*>} members
    
  333.    */
    
  334.   toIncludeAnyMembers(members: any[]): void,
    
  335. 
    
  336.   /**
    
  337.    * 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.
    
  338.    * @param {Function} predicate
    
  339.    */
    
  340.   toSatisfyAll(predicate: (n: any) => boolean): void,
    
  341. 
    
  342.   /**
    
  343.    * Use `.toBeBoolean` when checking if a value is a `Boolean`.
    
  344.    */
    
  345.   toBeBoolean(): void,
    
  346. 
    
  347.   /**
    
  348.    * Use `.toBeTrue` when checking a value is equal (===) to `true`.
    
  349.    */
    
  350.   toBeTrue(): void,
    
  351. 
    
  352.   /**
    
  353.    * Use `.toBeFalse` when checking a value is equal (===) to `false`.
    
  354.    */
    
  355.   toBeFalse(): void,
    
  356. 
    
  357.   /**
    
  358.    * Use .toBeDate when checking if a value is a Date.
    
  359.    */
    
  360.   toBeDate(): void,
    
  361. 
    
  362.   /**
    
  363.    * Use `.toBeFunction` when checking if a value is a `Function`.
    
  364.    */
    
  365.   toBeFunction(): void,
    
  366. 
    
  367.   /**
    
  368.    * Use `.toHaveBeenCalledBefore` when checking if a `Mock` was called before another `Mock`.
    
  369.    *
    
  370.    * Note: Required Jest version >22
    
  371.    * 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
    
  372.    *
    
  373.    * @param {Mock} mock
    
  374.    */
    
  375.   toHaveBeenCalledBefore(mock: JestMockFn<any, any>): void,
    
  376. 
    
  377.   /**
    
  378.    * Use `.toBeNumber` when checking if a value is a `Number`.
    
  379.    */
    
  380.   toBeNumber(): void,
    
  381. 
    
  382.   /**
    
  383.    * Use `.toBeNaN` when checking a value is `NaN`.
    
  384.    */
    
  385.   toBeNaN(): void,
    
  386. 
    
  387.   /**
    
  388.    * Use `.toBeFinite` when checking if a value is a `Number`, not `NaN` or `Infinity`.
    
  389.    */
    
  390.   toBeFinite(): void,
    
  391. 
    
  392.   /**
    
  393.    * Use `.toBePositive` when checking if a value is a positive `Number`.
    
  394.    */
    
  395.   toBePositive(): void,
    
  396. 
    
  397.   /**
    
  398.    * Use `.toBeNegative` when checking if a value is a negative `Number`.
    
  399.    */
    
  400.   toBeNegative(): void,
    
  401. 
    
  402.   /**
    
  403.    * Use `.toBeEven` when checking if a value is an even `Number`.
    
  404.    */
    
  405.   toBeEven(): void,
    
  406. 
    
  407.   /**
    
  408.    * Use `.toBeOdd` when checking if a value is an odd `Number`.
    
  409.    */
    
  410.   toBeOdd(): void,
    
  411. 
    
  412.   /**
    
  413.    * Use `.toBeWithin` when checking if a number is in between the given bounds of: start (inclusive) and end (exclusive).
    
  414.    *
    
  415.    * @param {Number} start
    
  416.    * @param {Number} end
    
  417.    */
    
  418.   toBeWithin(start: number, end: number): void,
    
  419. 
    
  420.   /**
    
  421.    * Use `.toBeObject` when checking if a value is an `Object`.
    
  422.    */
    
  423.   toBeObject(): void,
    
  424. 
    
  425.   /**
    
  426.    * Use `.toContainKey` when checking if an object contains the provided key.
    
  427.    *
    
  428.    * @param {String} key
    
  429.    */
    
  430.   toContainKey(key: string): void,
    
  431. 
    
  432.   /**
    
  433.    * Use `.toContainKeys` when checking if an object has all of the provided keys.
    
  434.    *
    
  435.    * @param {Array.<String>} keys
    
  436.    */
    
  437.   toContainKeys(keys: string[]): void,
    
  438. 
    
  439.   /**
    
  440.    * Use `.toContainAllKeys` when checking if an object only contains all of the provided keys.
    
  441.    *
    
  442.    * @param {Array.<String>} keys
    
  443.    */
    
  444.   toContainAllKeys(keys: string[]): void,
    
  445. 
    
  446.   /**
    
  447.    * Use `.toContainAnyKeys` when checking if an object contains at least one of the provided keys.
    
  448.    *
    
  449.    * @param {Array.<String>} keys
    
  450.    */
    
  451.   toContainAnyKeys(keys: string[]): void,
    
  452. 
    
  453.   /**
    
  454.    * Use `.toContainValue` when checking if an object contains the provided value.
    
  455.    *
    
  456.    * @param {*} value
    
  457.    */
    
  458.   toContainValue(value: any): void,
    
  459. 
    
  460.   /**
    
  461.    * Use `.toContainValues` when checking if an object contains all of the provided values.
    
  462.    *
    
  463.    * @param {Array.<*>} values
    
  464.    */
    
  465.   toContainValues(values: any[]): void,
    
  466. 
    
  467.   /**
    
  468.    * Use `.toContainAllValues` when checking if an object only contains all of the provided values.
    
  469.    *
    
  470.    * @param {Array.<*>} values
    
  471.    */
    
  472.   toContainAllValues(values: any[]): void,
    
  473. 
    
  474.   /**
    
  475.    * Use `.toContainAnyValues` when checking if an object contains at least one of the provided values.
    
  476.    *
    
  477.    * @param {Array.<*>} values
    
  478.    */
    
  479.   toContainAnyValues(values: any[]): void,
    
  480. 
    
  481.   /**
    
  482.    * Use `.toContainEntry` when checking if an object contains the provided entry.
    
  483.    *
    
  484.    * @param {Array.<String, String>} entry
    
  485.    */
    
  486.   toContainEntry(entry: [string, string]): void,
    
  487. 
    
  488.   /**
    
  489.    * Use `.toContainEntries` when checking if an object contains all of the provided entries.
    
  490.    *
    
  491.    * @param {Array.<Array.<String, String>>} entries
    
  492.    */
    
  493.   toContainEntries(entries: [string, string][]): void,
    
  494. 
    
  495.   /**
    
  496.    * Use `.toContainAllEntries` when checking if an object only contains all of the provided entries.
    
  497.    *
    
  498.    * @param {Array.<Array.<String, String>>} entries
    
  499.    */
    
  500.   toContainAllEntries(entries: [string, string][]): void,
    
  501. 
    
  502.   /**
    
  503.    * Use `.toContainAnyEntries` when checking if an object contains at least one of the provided entries.
    
  504.    *
    
  505.    * @param {Array.<Array.<String, String>>} entries
    
  506.    */
    
  507.   toContainAnyEntries(entries: [string, string][]): void,
    
  508. 
    
  509.   /**
    
  510.    * Use `.toBeExtensible` when checking if an object is extensible.
    
  511.    */
    
  512.   toBeExtensible(): void,
    
  513. 
    
  514.   /**
    
  515.    * Use `.toBeFrozen` when checking if an object is frozen.
    
  516.    */
    
  517.   toBeFrozen(): void,
    
  518. 
    
  519.   /**
    
  520.    * Use `.toBeSealed` when checking if an object is sealed.
    
  521.    */
    
  522.   toBeSealed(): void,
    
  523. 
    
  524.   /**
    
  525.    * Use `.toBeString` when checking if a value is a `String`.
    
  526.    */
    
  527.   toBeString(): void,
    
  528. 
    
  529.   /**
    
  530.    * Use `.toEqualCaseInsensitive` when checking if a string is equal (===) to another ignoring the casing of both strings.
    
  531.    *
    
  532.    * @param {String} string
    
  533.    */
    
  534.   toEqualCaseInsensitive(string: string): void,
    
  535. 
    
  536.   /**
    
  537.    * Use `.toStartWith` when checking if a `String` starts with a given `String` prefix.
    
  538.    *
    
  539.    * @param {String} prefix
    
  540.    */
    
  541.   toStartWith(prefix: string): void,
    
  542. 
    
  543.   /**
    
  544.    * Use `.toEndWith` when checking if a `String` ends with a given `String` suffix.
    
  545.    *
    
  546.    * @param {String} suffix
    
  547.    */
    
  548.   toEndWith(suffix: string): void,
    
  549. 
    
  550.   /**
    
  551.    * Use `.toInclude` when checking if a `String` includes the given `String` substring.
    
  552.    *
    
  553.    * @param {String} substring
    
  554.    */
    
  555.   toInclude(substring: string): void,
    
  556. 
    
  557.   /**
    
  558.    * Use `.toIncludeRepeated` when checking if a `String` includes the given `String` substring the correct number of times.
    
  559.    *
    
  560.    * @param {String} substring
    
  561.    * @param {Number} times
    
  562.    */
    
  563.   toIncludeRepeated(substring: string, times: number): void,
    
  564. 
    
  565.   /**
    
  566.    * Use `.toIncludeMultiple` when checking if a `String` includes all of the given substrings.
    
  567.    *
    
  568.    * @param {Array.<String>} substring
    
  569.    */
    
  570.   toIncludeMultiple(substring: string[]): void,
    
  571. };
    
  572. 
    
  573. interface JestExpectType {
    
  574.   not: JestExpectType &
    
  575.     EnzymeMatchersType &
    
  576.     DomTestingLibraryType &
    
  577.     JestJQueryMatchersType &
    
  578.     JestStyledComponentsMatchersType &
    
  579.     JestExtendedMatchersType;
    
  580.   /**
    
  581.    * If you have a mock function, you can use .lastCalledWith to test what
    
  582.    * arguments it was last called with.
    
  583.    */
    
  584.   lastCalledWith(...args: Array<any>): void;
    
  585.   /**
    
  586.    * toBe just checks that a value is what you expect. It uses === to check
    
  587.    * strict equality.
    
  588.    */
    
  589.   toBe(value: any): void;
    
  590.   /**
    
  591.    * Use .toBeCalledWith to ensure that a mock function was called with
    
  592.    * specific arguments.
    
  593.    */
    
  594.   toBeCalledWith(...args: Array<any>): void;
    
  595.   /**
    
  596.    * Using exact equality with floating point numbers is a bad idea. Rounding
    
  597.    * means that intuitive things fail.
    
  598.    */
    
  599.   toBeCloseTo(num: number, delta: any): void;
    
  600.   /**
    
  601.    * Use .toBeDefined to check that a variable is not undefined.
    
  602.    */
    
  603.   toBeDefined(): void;
    
  604.   /**
    
  605.    * Use .toBeFalsy when you don't care what a value is, you just want to
    
  606.    * ensure a value is false in a boolean context.
    
  607.    */
    
  608.   toBeFalsy(): void;
    
  609.   /**
    
  610.    * To compare floating point numbers, you can use toBeGreaterThan.
    
  611.    */
    
  612.   toBeGreaterThan(number: number): void;
    
  613.   /**
    
  614.    * To compare floating point numbers, you can use toBeGreaterThanOrEqual.
    
  615.    */
    
  616.   toBeGreaterThanOrEqual(number: number): void;
    
  617.   /**
    
  618.    * To compare floating point numbers, you can use toBeLessThan.
    
  619.    */
    
  620.   toBeLessThan(number: number): void;
    
  621.   /**
    
  622.    * To compare floating point numbers, you can use toBeLessThanOrEqual.
    
  623.    */
    
  624.   toBeLessThanOrEqual(number: number): void;
    
  625.   /**
    
  626.    * Use .toBeInstanceOf(Class) to check that an object is an instance of a
    
  627.    * class.
    
  628.    */
    
  629.   toBeInstanceOf(cls: Class<any>): void;
    
  630.   /**
    
  631.    * .toBeNull() is the same as .toBe(null) but the error messages are a bit
    
  632.    * nicer.
    
  633.    */
    
  634.   toBeNull(): void;
    
  635.   /**
    
  636.    * Use .toBeTruthy when you don't care what a value is, you just want to
    
  637.    * ensure a value is true in a boolean context.
    
  638.    */
    
  639.   toBeTruthy(): void;
    
  640.   /**
    
  641.    * Use .toBeUndefined to check that a variable is undefined.
    
  642.    */
    
  643.   toBeUndefined(): void;
    
  644.   /**
    
  645.    * Use .toContain when you want to check that an item is in a list. For
    
  646.    * testing the items in the list, this uses ===, a strict equality check.
    
  647.    */
    
  648.   toContain(item: any): void;
    
  649.   /**
    
  650.    * Use .toContainEqual when you want to check that an item is in a list. For
    
  651.    * testing the items in the list, this matcher recursively checks the
    
  652.    * equality of all fields, rather than checking for object identity.
    
  653.    */
    
  654.   toContainEqual(item: any): void;
    
  655.   /**
    
  656.    * Use .toEqual when you want to check that two objects have the same value.
    
  657.    * This matcher recursively checks the equality of all fields, rather than
    
  658.    * checking for object identity.
    
  659.    */
    
  660.   toEqual(value: any): void;
    
  661.   /**
    
  662.    * Use .toHaveBeenCalled to ensure that a mock function got called.
    
  663.    */
    
  664.   toHaveBeenCalled(): void;
    
  665.   toBeCalled(): void;
    
  666.   /**
    
  667.    * Use .toHaveBeenCalledTimes to ensure that a mock function got called exact
    
  668.    * number of times.
    
  669.    */
    
  670.   toHaveBeenCalledTimes(number: number): void;
    
  671.   toBeCalledTimes(number: number): void;
    
  672.   /**
    
  673.    *
    
  674.    */
    
  675.   toHaveBeenNthCalledWith(nthCall: number, ...args: Array<any>): void;
    
  676.   nthCalledWith(nthCall: number, ...args: Array<any>): void;
    
  677.   /**
    
  678.    *
    
  679.    */
    
  680.   toHaveReturned(): void;
    
  681.   toReturn(): void;
    
  682.   /**
    
  683.    *
    
  684.    */
    
  685.   toHaveReturnedTimes(number: number): void;
    
  686.   toReturnTimes(number: number): void;
    
  687.   /**
    
  688.    *
    
  689.    */
    
  690.   toHaveReturnedWith(value: any): void;
    
  691.   toReturnWith(value: any): void;
    
  692.   /**
    
  693.    *
    
  694.    */
    
  695.   toHaveLastReturnedWith(value: any): void;
    
  696.   lastReturnedWith(value: any): void;
    
  697.   /**
    
  698.    *
    
  699.    */
    
  700.   toHaveNthReturnedWith(nthCall: number, value: any): void;
    
  701.   nthReturnedWith(nthCall: number, value: any): void;
    
  702.   /**
    
  703.    * Use .toHaveBeenCalledWith to ensure that a mock function was called with
    
  704.    * specific arguments.
    
  705.    */
    
  706.   toHaveBeenCalledWith(...args: Array<any>): void;
    
  707.   /**
    
  708.    * Use .toHaveBeenLastCalledWith to ensure that a mock function was last called
    
  709.    * with specific arguments.
    
  710.    */
    
  711.   toHaveBeenLastCalledWith(...args: Array<any>): void;
    
  712.   /**
    
  713.    * Check that an object has a .length property and it is set to a certain
    
  714.    * numeric value.
    
  715.    */
    
  716.   toHaveLength(number: number): void;
    
  717.   /**
    
  718.    *
    
  719.    */
    
  720.   toHaveProperty(propPath: string, value?: any): void;
    
  721.   /**
    
  722.    * Use .toMatch to check that a string matches a regular expression or string.
    
  723.    */
    
  724.   toMatch(regexpOrString: RegExp | string): void;
    
  725.   /**
    
  726.    * Use .toMatchObject to check that a javascript object matches a subset of the properties of an object.
    
  727.    */
    
  728.   toMatchObject(object: Object | Array<Object>): void;
    
  729.   /**
    
  730.    * Use .toStrictEqual to check that a javascript object matches a subset of the properties of an object.
    
  731.    */
    
  732.   toStrictEqual(value: any): void;
    
  733.   /**
    
  734.    * This ensures that an Object matches the most recent snapshot.
    
  735.    */
    
  736.   toMatchSnapshot(propertyMatchers?: any, name?: string): void;
    
  737.   /**
    
  738.    * This ensures that an Object matches the most recent snapshot.
    
  739.    */
    
  740.   toMatchSnapshot(name: string): void;
    
  741. 
    
  742.   toMatchInlineSnapshot(snapshot?: string): void;
    
  743.   toMatchInlineSnapshot(propertyMatchers?: any, snapshot?: string): void;
    
  744.   /**
    
  745.    * Use .toThrow to test that a function throws when it is called.
    
  746.    * If you want to test that a specific error gets thrown, you can provide an
    
  747.    * argument to toThrow. The argument can be a string for the error message,
    
  748.    * a class for the error, or a regex that should match the error.
    
  749.    *
    
  750.    * Alias: .toThrowError
    
  751.    */
    
  752.   toThrow(message?: string | Error | Class<Error> | RegExp): void;
    
  753.   toThrowError(message?: string | Error | Class<Error> | RegExp): void;
    
  754.   /**
    
  755.    * Use .toThrowErrorMatchingSnapshot to test that a function throws a error
    
  756.    * matching the most recent snapshot when it is called.
    
  757.    */
    
  758.   toThrowErrorMatchingSnapshot(): void;
    
  759.   toThrowErrorMatchingInlineSnapshot(snapshot?: string): void;
    
  760. }
    
  761. 
    
  762. type JestObjectType = {
    
  763.   /**
    
  764.    *  Disables automatic mocking in the module loader.
    
  765.    *
    
  766.    *  After this method is called, all `require()`s will return the real
    
  767.    *  versions of each module (rather than a mocked version).
    
  768.    */
    
  769.   disableAutomock(): JestObjectType,
    
  770.   /**
    
  771.    * An un-hoisted version of disableAutomock
    
  772.    */
    
  773.   autoMockOff(): JestObjectType,
    
  774.   /**
    
  775.    * Enables automatic mocking in the module loader.
    
  776.    */
    
  777.   enableAutomock(): JestObjectType,
    
  778.   /**
    
  779.    * An un-hoisted version of enableAutomock
    
  780.    */
    
  781.   autoMockOn(): JestObjectType,
    
  782.   /**
    
  783.    * Clears the mock.calls and mock.instances properties of all mocks.
    
  784.    * Equivalent to calling .mockClear() on every mocked function.
    
  785.    */
    
  786.   clearAllMocks(): JestObjectType,
    
  787.   /**
    
  788.    * Resets the state of all mocks. Equivalent to calling .mockReset() on every
    
  789.    * mocked function.
    
  790.    */
    
  791.   resetAllMocks(): JestObjectType,
    
  792.   /**
    
  793.    * Restores all mocks back to their original value.
    
  794.    */
    
  795.   restoreAllMocks(): JestObjectType,
    
  796.   /**
    
  797.    * Removes any pending timers from the timer system.
    
  798.    */
    
  799.   clearAllTimers(): void,
    
  800.   /**
    
  801.    * Returns the number of fake timers still left to run.
    
  802.    */
    
  803.   getTimerCount(): number,
    
  804.   /**
    
  805.    * The same as `mock` but not moved to the top of the expectation by
    
  806.    * babel-jest.
    
  807.    */
    
  808.   doMock(moduleName: string, moduleFactory?: any): JestObjectType,
    
  809.   /**
    
  810.    * The same as `unmock` but not moved to the top of the expectation by
    
  811.    * babel-jest.
    
  812.    */
    
  813.   dontMock(moduleName: string): JestObjectType,
    
  814.   /**
    
  815.    * Returns a new, unused mock function. Optionally takes a mock
    
  816.    * implementation.
    
  817.    */
    
  818.   fn<TArguments: $ReadOnlyArray<any>, TReturn>(
    
  819.     implementation?: (...args: TArguments) => TReturn
    
  820.   ): JestMockFn<TArguments, TReturn>,
    
  821.   /**
    
  822.    * Determines if the given function is a mocked function.
    
  823.    */
    
  824.   isMockFunction(fn: Function): boolean,
    
  825.   /**
    
  826.    * Given the name of a module, use the automatic mocking system to generate a
    
  827.    * mocked version of the module for you.
    
  828.    */
    
  829.   genMockFromModule(moduleName: string): any,
    
  830.   /**
    
  831.    * Mocks a module with an auto-mocked version when it is being required.
    
  832.    *
    
  833.    * The second argument can be used to specify an explicit module factory that
    
  834.    * is being run instead of using Jest's automocking feature.
    
  835.    *
    
  836.    * The third argument can be used to create virtual mocks -- mocks of modules
    
  837.    * that don't exist anywhere in the system.
    
  838.    */
    
  839.   mock(
    
  840.     moduleName: string,
    
  841.     moduleFactory?: any,
    
  842.     options?: Object
    
  843.   ): JestObjectType,
    
  844.   /**
    
  845.    * Returns the actual module instead of a mock, bypassing all checks on
    
  846.    * whether the module should receive a mock implementation or not.
    
  847.    */
    
  848.   requireActual(moduleName: string): any,
    
  849.   /**
    
  850.    * Returns a mock module instead of the actual module, bypassing all checks
    
  851.    * on whether the module should be required normally or not.
    
  852.    */
    
  853.   requireMock(moduleName: string): any,
    
  854.   /**
    
  855.    * Resets the module registry - the cache of all required modules. This is
    
  856.    * useful to isolate modules where local state might conflict between tests.
    
  857.    */
    
  858.   resetModules(): JestObjectType,
    
  859. 
    
  860.   /**
    
  861.    * Creates a sandbox registry for the modules that are loaded inside the
    
  862.    * callback function. This is useful to isolate specific modules for every
    
  863.    * test so that local module state doesn't conflict between tests.
    
  864.    */
    
  865.   isolateModules(fn: () => void): JestObjectType,
    
  866. 
    
  867.   /**
    
  868.    * Exhausts the micro-task queue (usually interfaced in node via
    
  869.    * process.nextTick).
    
  870.    */
    
  871.   runAllTicks(): void,
    
  872.   /**
    
  873.    * Exhausts the macro-task queue (i.e., all tasks queued by setTimeout(),
    
  874.    * setInterval(), and setImmediate()).
    
  875.    */
    
  876.   runAllTimers(): void,
    
  877.   /**
    
  878.    * Exhausts all tasks queued by setImmediate().
    
  879.    */
    
  880.   runAllImmediates(): void,
    
  881.   /**
    
  882.    * Executes only the macro task queue (i.e. all tasks queued by setTimeout()
    
  883.    * or setInterval() and setImmediate()).
    
  884.    */
    
  885.   advanceTimersByTime(msToRun: number): void,
    
  886.   /**
    
  887.    * Executes only the macro task queue (i.e. all tasks queued by setTimeout()
    
  888.    * or setInterval() and setImmediate()).
    
  889.    *
    
  890.    * Renamed to `advanceTimersByTime`.
    
  891.    */
    
  892.   runTimersToTime(msToRun: number): void,
    
  893.   /**
    
  894.    * Executes only the macro-tasks that are currently pending (i.e., only the
    
  895.    * tasks that have been queued by setTimeout() or setInterval() up to this
    
  896.    * point)
    
  897.    */
    
  898.   runOnlyPendingTimers(): void,
    
  899.   /**
    
  900.    * Explicitly supplies the mock object that the module system should return
    
  901.    * for the specified module. Note: It is recommended to use jest.mock()
    
  902.    * instead.
    
  903.    */
    
  904.   setMock(moduleName: string, moduleExports: any): JestObjectType,
    
  905.   /**
    
  906.    * Indicates that the module system should never return a mocked version of
    
  907.    * the specified module from require() (e.g. that it should always return the
    
  908.    * real module).
    
  909.    */
    
  910.   unmock(moduleName: string): JestObjectType,
    
  911.   /**
    
  912.    * Instructs Jest to use fake versions of the standard timer functions
    
  913.    * (setTimeout, setInterval, clearTimeout, clearInterval, nextTick,
    
  914.    * setImmediate and clearImmediate).
    
  915.    */
    
  916.   useFakeTimers(): JestObjectType,
    
  917.   /**
    
  918.    * Instructs Jest to use the real versions of the standard timer functions.
    
  919.    */
    
  920.   useRealTimers(): JestObjectType,
    
  921.   /**
    
  922.    * Creates a mock function similar to jest.fn but also tracks calls to
    
  923.    * object[methodName].
    
  924.    */
    
  925.   spyOn(
    
  926.     object: Object,
    
  927.     methodName: string,
    
  928.     accessType?: 'get' | 'set'
    
  929.   ): JestMockFn<any, any>,
    
  930.   /**
    
  931.    * Set the default timeout interval for tests and before/after hooks in milliseconds.
    
  932.    * Note: The default timeout interval is 5 seconds if this method is not called.
    
  933.    */
    
  934.   setTimeout(timeout: number): JestObjectType,
    
  935. };
    
  936. 
    
  937. type JestSpyType = {
    
  938.   calls: JestCallsType,
    
  939. };
    
  940. 
    
  941. /** Runs this function after every test inside this context */
    
  942. declare function afterEach(
    
  943.   fn: (done: () => void) => ?Promise<mixed>,
    
  944.   timeout?: number
    
  945. ): void;
    
  946. /** Runs this function before every test inside this context */
    
  947. declare function beforeEach(
    
  948.   fn: (done: () => void) => ?Promise<mixed>,
    
  949.   timeout?: number
    
  950. ): void;
    
  951. /** Runs this function after all tests have finished inside this context */
    
  952. declare function afterAll(
    
  953.   fn: (done: () => void) => ?Promise<mixed>,
    
  954.   timeout?: number
    
  955. ): void;
    
  956. /** Runs this function before any tests have started inside this context */
    
  957. declare function beforeAll(
    
  958.   fn: (done: () => void) => ?Promise<mixed>,
    
  959.   timeout?: number
    
  960. ): void;
    
  961. 
    
  962. /** A context for grouping tests together */
    
  963. declare var describe: {
    
  964.   /**
    
  965.    * Creates a block that groups together several related tests in one "test suite"
    
  966.    */
    
  967.   (name: JestTestName, fn: () => void): void,
    
  968. 
    
  969.   /**
    
  970.    * Only run this describe block
    
  971.    */
    
  972.   only(name: JestTestName, fn: () => void): void,
    
  973. 
    
  974.   /**
    
  975.    * Skip running this describe block
    
  976.    */
    
  977.   skip(name: JestTestName, fn: () => void): void,
    
  978. 
    
  979.   /**
    
  980.    * each runs this test against array of argument arrays per each run
    
  981.    *
    
  982.    * @param {table} table of Test
    
  983.    */
    
  984.   each(
    
  985.     ...table: Array<Array<mixed> | mixed> | [Array<string>, string]
    
  986.   ): (
    
  987.     name: JestTestName,
    
  988.     fn?: (...args: Array<any>) => ?Promise<mixed>,
    
  989.     timeout?: number
    
  990.   ) => void,
    
  991. };
    
  992. 
    
  993. /** An individual test unit */
    
  994. declare var it: {
    
  995.   /**
    
  996.    * An individual test unit
    
  997.    *
    
  998.    * @param {JestTestName} Name of Test
    
  999.    * @param {Function} Test
    
  1000.    * @param {number} Timeout for the test, in milliseconds.
    
  1001.    */
    
  1002.   (
    
  1003.     name: JestTestName,
    
  1004.     fn?: (done: () => void) => ?Promise<mixed>,
    
  1005.     timeout?: number
    
  1006.   ): void,
    
  1007. 
    
  1008.   /**
    
  1009.    * Only run this test
    
  1010.    *
    
  1011.    * @param {JestTestName} Name of Test
    
  1012.    * @param {Function} Test
    
  1013.    * @param {number} Timeout for the test, in milliseconds.
    
  1014.    */
    
  1015.   only(
    
  1016.     name: JestTestName,
    
  1017.     fn?: (done: () => void) => ?Promise<mixed>,
    
  1018.     timeout?: number
    
  1019.   ): {
    
  1020.     each(
    
  1021.       ...table: Array<Array<mixed> | mixed> | [Array<string>, string]
    
  1022.     ): (
    
  1023.       name: JestTestName,
    
  1024.       fn?: (...args: Array<any>) => ?Promise<mixed>,
    
  1025.       timeout?: number
    
  1026.     ) => void,
    
  1027.   },
    
  1028. 
    
  1029.   /**
    
  1030.    * Skip running this test
    
  1031.    *
    
  1032.    * @param {JestTestName} Name of Test
    
  1033.    * @param {Function} Test
    
  1034.    * @param {number} Timeout for the test, in milliseconds.
    
  1035.    */
    
  1036.   skip(
    
  1037.     name: JestTestName,
    
  1038.     fn?: (done: () => void) => ?Promise<mixed>,
    
  1039.     timeout?: number
    
  1040.   ): void,
    
  1041. 
    
  1042.   /**
    
  1043.    * Highlight planned tests in the summary output
    
  1044.    *
    
  1045.    * @param {String} Name of Test to do
    
  1046.    */
    
  1047.   todo(name: string): void,
    
  1048. 
    
  1049.   /**
    
  1050.    * Run the test concurrently
    
  1051.    *
    
  1052.    * @param {JestTestName} Name of Test
    
  1053.    * @param {Function} Test
    
  1054.    * @param {number} Timeout for the test, in milliseconds.
    
  1055.    */
    
  1056.   concurrent(
    
  1057.     name: JestTestName,
    
  1058.     fn?: (done: () => void) => ?Promise<mixed>,
    
  1059.     timeout?: number
    
  1060.   ): void,
    
  1061. 
    
  1062.   /**
    
  1063.    * each runs this test against array of argument arrays per each run
    
  1064.    *
    
  1065.    * @param {table} table of Test
    
  1066.    */
    
  1067.   each(
    
  1068.     ...table: Array<Array<mixed> | mixed> | [Array<string>, string]
    
  1069.   ): (
    
  1070.     name: JestTestName,
    
  1071.     fn?: (...args: Array<any>) => ?Promise<mixed>,
    
  1072.     timeout?: number
    
  1073.   ) => void,
    
  1074. };
    
  1075. 
    
  1076. declare function fit(
    
  1077.   name: JestTestName,
    
  1078.   fn: (done: () => void) => ?Promise<mixed>,
    
  1079.   timeout?: number
    
  1080. ): void;
    
  1081. /** An individual test unit */
    
  1082. declare var test: typeof it;
    
  1083. /** A disabled group of tests */
    
  1084. declare var xdescribe: typeof describe;
    
  1085. /** A focused group of tests */
    
  1086. declare var fdescribe: typeof describe;
    
  1087. /** A disabled individual test */
    
  1088. declare var xit: typeof it;
    
  1089. /** A disabled individual test */
    
  1090. declare var xtest: typeof it;
    
  1091. 
    
  1092. type JestPrettyFormatColors = {
    
  1093.   comment: {close: string, open: string},
    
  1094.   content: {close: string, open: string},
    
  1095.   prop: {close: string, open: string},
    
  1096.   tag: {close: string, open: string},
    
  1097.   value: {close: string, open: string},
    
  1098. };
    
  1099. 
    
  1100. type JestPrettyFormatIndent = string => string;
    
  1101. // eslint-disable-next-line no-unused-vars
    
  1102. type JestPrettyFormatRefs = Array<any>;
    
  1103. type JestPrettyFormatPrint = any => string;
    
  1104. // eslint-disable-next-line no-unused-vars
    
  1105. type JestPrettyFormatStringOrNull = string | null;
    
  1106. 
    
  1107. type JestPrettyFormatOptions = {
    
  1108.   callToJSON: boolean,
    
  1109.   edgeSpacing: string,
    
  1110.   escapeRegex: boolean,
    
  1111.   highlight: boolean,
    
  1112.   indent: number,
    
  1113.   maxDepth: number,
    
  1114.   min: boolean,
    
  1115.   // eslint-disable-next-line no-use-before-define
    
  1116.   plugins: JestPrettyFormatPlugins,
    
  1117.   printFunctionName: boolean,
    
  1118.   spacing: string,
    
  1119.   theme: {
    
  1120.     comment: string,
    
  1121.     content: string,
    
  1122.     prop: string,
    
  1123.     tag: string,
    
  1124.     value: string,
    
  1125.   },
    
  1126. };
    
  1127. 
    
  1128. type JestPrettyFormatPlugin = {
    
  1129.   print: (
    
  1130.     val: any,
    
  1131.     serialize: JestPrettyFormatPrint,
    
  1132.     indent: JestPrettyFormatIndent,
    
  1133.     opts: JestPrettyFormatOptions,
    
  1134.     colors: JestPrettyFormatColors
    
  1135.   ) => string,
    
  1136.   test: any => boolean,
    
  1137. };
    
  1138. 
    
  1139. type JestPrettyFormatPlugins = Array<JestPrettyFormatPlugin>;
    
  1140. 
    
  1141. /** The expect function is used every time you want to test a value */
    
  1142. declare var expect: {
    
  1143.   /** The object that you want to make assertions against */
    
  1144.   (
    
  1145.     value: any
    
  1146.   ): JestExpectType &
    
  1147.     JestPromiseType &
    
  1148.     EnzymeMatchersType &
    
  1149.     DomTestingLibraryType &
    
  1150.     JestJQueryMatchersType &
    
  1151.     JestStyledComponentsMatchersType &
    
  1152.     JestExtendedMatchersType,
    
  1153. 
    
  1154.   /** Add additional Jasmine matchers to Jest's roster */
    
  1155.   extend(matchers: {[name: string]: JestMatcher}): void,
    
  1156.   /** Add a module that formats application-specific data structures. */
    
  1157.   addSnapshotSerializer(pluginModule: JestPrettyFormatPlugin): void,
    
  1158.   assertions(expectedAssertions: number): void,
    
  1159.   hasAssertions(): void,
    
  1160.   any(value: mixed): JestAsymmetricEqualityType,
    
  1161.   anything(): any,
    
  1162.   arrayContaining(value: Array<mixed>): Array<mixed>,
    
  1163.   objectContaining(value: Object): Object,
    
  1164.   /** Matches any received string that contains the exact expected string. */
    
  1165.   stringContaining(value: string): string,
    
  1166.   stringMatching(value: string | RegExp): string,
    
  1167.   not: {
    
  1168.     arrayContaining: (value: $ReadOnlyArray<mixed>) => Array<mixed>,
    
  1169.     objectContaining: (value: {}) => Object,
    
  1170.     stringContaining: (value: string) => string,
    
  1171.     stringMatching: (value: string | RegExp) => string,
    
  1172.   },
    
  1173. };
    
  1174. 
    
  1175. /** Holds all functions related to manipulating test runner */
    
  1176. declare var jest: JestObjectType;