diff --git a/jest/jest-tests.ts b/jest/jest-tests.ts index da141ef9e..f3e33c406 100644 --- a/jest/jest-tests.ts +++ b/jest/jest-tests.ts @@ -1,7 +1,7 @@ /// // Tests based on the Jest website -jest.dontMock('../sum'); +jest.unmock('../sum'); describe('sum', function() { it('adds 1 + 2 to equal 3', function() { @@ -16,7 +16,7 @@ describe('fetchCurrentUser', function() { var fetchCurrentUser = require('../fetchCurrentUser'); // Create a mock function for our callback - var callback = jest.genMockFunction(); + var callback = jest.fn(); fetchCurrentUser(callback); // Now we emulate the process by which `$.ajax` would execute its own @@ -35,7 +35,9 @@ describe('fetchCurrentUser', function() { }); }); -jest.dontMock('../displayUser.js') +// unmock is the recommended approach for unmocking... +jest.unmock('../displayUser.js') +// ...but dontMock also still works. jest.dontMock('jquery'); describe('displayUser', function() { @@ -70,7 +72,7 @@ describe('displayUser', function() { }); }); -jest.dontMock('../CheckboxWithLabel.js'); +jest.unmock('../CheckboxWithLabel.js'); describe('CheckboxWithLabel', function() { it('changes the text after click', function() { var React = require('react/addons'); @@ -99,7 +101,7 @@ describe('CheckboxWithLabel', function() { }); function testInstances() { - var mockFn = jest.genMockFunction(); + var mockFn = jest.fn(); var a = new mockFn(); var b = new mockFn(); @@ -108,7 +110,7 @@ function testInstances() { } function testMockImplementation() { - var mockFn = jest.genMockFunction().mockImplementation(function (scalar:number):number { + var mockFn = jest.fn().mockImplementation(function (scalar:number):number { return 42 + scalar; }); @@ -120,4 +122,4 @@ function testMockImplementation() { mockFn.mock.calls[0][0] === 0; // true mockFn.mock.calls[1][0] === 1; // true -} \ No newline at end of file +} diff --git a/jest/jest.d.ts b/jest/jest.d.ts index d236d07db..033dd23fa 100644 --- a/jest/jest.d.ts +++ b/jest/jest.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Jest 0.1.18 +// Type definitions for Jest 0.9.0 // Project: http://facebook.github.io/jest/ // Definitions by: Asana // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -26,15 +26,15 @@ declare namespace jest { function autoMockOn(): void; function clearAllTimers(): void; function currentTestPath(): string; + function fn(implementation?: Function): Mock; function dontMock(moduleName: string): void; function genMockFromModule(moduleName: string): Mock; - function genMockFunction(): Mock; - function genMockFn(): Mock; function mock(moduleName: string): void; function runAllTicks(): void; function runAllTimers(): void; function runOnlyPendingTimers(): void; function setMock(moduleName: string, moduleExports: T): void; + function unmock(moduleName: string): void; interface EmptyFunction { (): void;