add jest mockName and getMockName (#22682)

This commit is contained in:
Chris Mohr
2018-01-04 14:31:11 -08:00
committed by Mohamed Hegazy
parent d6eafb8ea0
commit 9a4a3b6418
2 changed files with 9 additions and 1 deletions
+2
View File
@@ -533,6 +533,8 @@ declare namespace jest {
mockReturnThis(): Mock<T>;
mockReturnValue(value: any): Mock<T>;
mockReturnValueOnce(value: any): Mock<T>;
mockName(name: string): Mock<T>;
getMockName(): string;
}
interface MockContext<T> {
+7 -1
View File
@@ -311,7 +311,7 @@ describe('missing tests', () => {
expect(jest.isMockFunction(spy)).toBeTruthy();
});
it('tests all mising Mocks functionality', () => {
it('tests all missing Mocks functionality', () => {
type FruitsGetter = () => string[];
const mock: jest.Mock<FruitsGetter> = jest.fn<FruitsGetter>();
mock.mockImplementationOnce(() => ['Orange', 'Apple', 'Plum']);
@@ -328,6 +328,12 @@ describe('missing tests', () => {
expect(thisMock()).toBe(this);
});
it('tests mock name functionality', () => {
const mock: jest.Mock = jest.fn();
mock.mockName('Carrot');
expect(mock.getMockName()).toBe('Carrot');
});
it('creates snapshoter', () => {
jest.disableAutomock().mock('./render', () => jest.fn((): string => "{Link to: \"facebook\"}"), { virtual: true });
const render: () => string = require('./render');