Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d4595e
commit 5f610f9
Showing
10 changed files
with
149 additions
and
46 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import type {Jest} from '@jest/environment'; | ||
import type {JestExpect} from '@jest/expect'; | ||
import type {Global} from '@jest/types'; | ||
|
||
export declare const jest: Jest; | ||
|
||
export declare const expect: JestExpect; | ||
|
||
export declare const test: Global.GlobalAdditions['test']; | ||
export declare const xtest: Global.GlobalAdditions['xtest']; | ||
|
||
export declare const it: Global.GlobalAdditions['it']; | ||
export declare const fit: Global.GlobalAdditions['fit']; | ||
export declare const xit: Global.GlobalAdditions['xit']; | ||
|
||
export declare const describe: Global.GlobalAdditions['describe']; | ||
export declare const fdescribe: Global.GlobalAdditions['fdescribe']; | ||
export declare const xdescribe: Global.GlobalAdditions['xdescribe']; | ||
|
||
export declare const beforeAll: Global.GlobalAdditions['beforeAll']; | ||
export declare const beforeEach: Global.GlobalAdditions['beforeEach']; | ||
|
||
export declare const afterEach: Global.GlobalAdditions['afterEach']; | ||
export declare const afterAll: Global.GlobalAdditions['afterAll']; | ||
|
||
declare namespace jest { | ||
/** | ||
* Wraps an object or a module with mock definitions. | ||
* | ||
* @example | ||
* | ||
* jest.mock('../api'); | ||
* import * as api from '../api'; | ||
* | ||
* const mockApi = api as jest.Mocked<typeof api>; | ||
* | ||
* api.MyApi.prototype.myApiMethod.mockImplementation(() => 'test'); | ||
*/ | ||
export type Mocked<T> = import('jest-mock').Mocked<T>; | ||
|
||
/** | ||
* Wraps a class with mock definitions. | ||
* | ||
* @example | ||
* | ||
* import {MyClass} from './library'; | ||
* jest.mock('./library'); | ||
* | ||
* const mockMyClass = MyClass as jest.MockedClass<typeof MyClass>; | ||
* | ||
* expect(mockMyClass.mock.calls[0][0]).toBe(42); // Constructor calls | ||
* expect(mockMyClass.prototype.myMethod.mock.calls[0][0]).toBe(42); // Method calls | ||
*/ | ||
export type MockedClass<T> = import('jest-mock').MockedClass<T>; | ||
|
||
/** | ||
* Wraps a function with mock definitions. | ||
* | ||
* @example | ||
* | ||
* import {myFunction} from './library'; | ||
* jest.mock('./library'); | ||
* | ||
* const mockMyFunction = myFunction as jest.MockedFunction<typeof myFunction>; | ||
* | ||
* expect(mockMyFunction.mock.calls[0][0]).toBe(42); | ||
*/ | ||
export type MockedFunction<T> = import('jest-mock').MockedFunction<T>; | ||
|
||
/** | ||
* Wraps a function with spy definitions. | ||
*/ | ||
export type SpiedFunction<T> = import('jest-mock').SpiedFunction<T>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
throw new Error( | ||
'Do not import `@jest/globals` outside of the Jest test environment' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {expectType} from 'tsd-lite'; | ||
import {jest} from '@jest/globals'; | ||
import type {Mock} from 'jest-mock'; | ||
|
||
// Mock | ||
|
||
const mock1: Mock<number> = jest.fn(); | ||
|
||
expectType<Mock<number>>(mock1); | ||
|
||
// MockedFunction | ||
|
||
function testFunction(num: number, str: string): boolean { | ||
return true; | ||
} | ||
|
||
const mockedTestFunction = testFunction as jest.MockedFunction< | ||
typeof testFunction | ||
>; | ||
|
||
expectType<number>(mockedTestFunction.mock.calls[0][0]); | ||
expectType<string>(mockedTestFunction.mock.calls[0][1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters