Skip to content

Commit 1fad2ff

Browse files
committed
Update jest type definitions to 0.9.0
Add new functions and remove functions that have been dropped. From api documentation regarding unmock/dontMock: Note: this method was previously called dontMock. When using babel-jest, calls to unmock will automatically be hoisted to the top of the code block. You can use dontMock if you want to explicitly avoid this behavior.
1 parent 552fe5d commit 1fad2ff

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

jest/jest-tests.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="jest.d.ts" />
22

33
// Tests based on the Jest website
4-
jest.dontMock('../sum');
4+
jest.unmock('../sum');
55

66
describe('sum', function() {
77
it('adds 1 + 2 to equal 3', function() {
@@ -16,7 +16,7 @@ describe('fetchCurrentUser', function() {
1616
var fetchCurrentUser = require('../fetchCurrentUser');
1717

1818
// Create a mock function for our callback
19-
var callback = jest.genMockFunction();
19+
var callback = jest.fn();
2020
fetchCurrentUser(callback);
2121

2222
// Now we emulate the process by which `$.ajax` would execute its own
@@ -35,7 +35,9 @@ describe('fetchCurrentUser', function() {
3535
});
3636
});
3737

38-
jest.dontMock('../displayUser.js')
38+
// unmock is the recommended approach for unmocking...
39+
jest.unmock('../displayUser.js')
40+
// ...but dontMock also still works.
3941
jest.dontMock('jquery');
4042

4143
describe('displayUser', function() {
@@ -70,7 +72,7 @@ describe('displayUser', function() {
7072
});
7173
});
7274

73-
jest.dontMock('../CheckboxWithLabel.js');
75+
jest.unmock('../CheckboxWithLabel.js');
7476
describe('CheckboxWithLabel', function() {
7577
it('changes the text after click', function() {
7678
var React = require('react/addons');
@@ -99,7 +101,7 @@ describe('CheckboxWithLabel', function() {
99101
});
100102

101103
function testInstances() {
102-
var mockFn = jest.genMockFunction<Function>();
104+
var mockFn = jest.fn<Function>();
103105
var a = new mockFn();
104106
var b = new mockFn();
105107

@@ -108,7 +110,7 @@ function testInstances() {
108110
}
109111

110112
function testMockImplementation() {
111-
var mockFn = jest.genMockFunction<Function>().mockImplementation(function (scalar:number):number {
113+
var mockFn = jest.fn<Function>().mockImplementation(function (scalar:number):number {
112114
return 42 + scalar;
113115
});
114116

@@ -120,4 +122,4 @@ function testMockImplementation() {
120122

121123
mockFn.mock.calls[0][0] === 0; // true
122124
mockFn.mock.calls[1][0] === 1; // true
123-
}
125+
}

jest/jest.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for Jest 0.1.18
1+
// Type definitions for Jest 0.9.0
22
// Project: http://facebook.github.io/jest/
33
// Definitions by: Asana <https://asana.com>
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -26,15 +26,15 @@ declare module jest {
2626
function autoMockOn(): void;
2727
function clearAllTimers(): void;
2828
function currentTestPath(): string;
29+
function fn<T>(implementation?: Function): Mock<T>;
2930
function dontMock(moduleName: string): void;
3031
function genMockFromModule<T>(moduleName: string): Mock<T>;
31-
function genMockFunction<T>(): Mock<T>;
32-
function genMockFn<T>(): Mock<T>;
3332
function mock(moduleName: string): void;
3433
function runAllTicks(): void;
3534
function runAllTimers(): void;
3635
function runOnlyPendingTimers(): void;
3736
function setMock<T>(moduleName: string, moduleExports: T): void;
37+
function unmock(moduleName: string): void;
3838

3939
interface EmptyFunction {
4040
(): void;

0 commit comments

Comments
 (0)