replace expect.createSpy() with jest.fn()

Signed-off-by: Stephen Solka <stephen0q@gmail.com>
pull/21833/head
Stephen Solka 2018-12-24 21:55:10 -05:00 committed by J. Ryan Stinnett
parent c3185a4cdb
commit 0bb35944f9
5 changed files with 25 additions and 21 deletions

View File

@ -126,6 +126,7 @@
"estree-walker": "^0.5.0", "estree-walker": "^0.5.0",
"expect": "^23.6.0", "expect": "^23.6.0",
"flow-parser": "^0.57.3", "flow-parser": "^0.57.3",
"jest-mock": "^23.2.0",
"karma": "^3.0.0", "karma": "^3.0.0",
"karma-chrome-launcher": "^0.2.3", "karma-chrome-launcher": "^0.2.3",
"karma-cli": "^1.0.1", "karma-cli": "^1.0.1",

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const jest = require('jest-mock');
const React = require('react'); const React = require('react');
const ReactDOM = require('react-dom'); const ReactDOM = require('react-dom');
const ReactTestUtils = require('react-addons-test-utils'); const ReactTestUtils = require('react-addons-test-utils');
@ -87,8 +88,8 @@ describe('Registration', function() {
}); });
it('should NOT track a referral following successful registration of a non-team member', function(done) { it('should NOT track a referral following successful registration of a non-team member', function(done) {
const onLoggedIn = expect.createSpy().andCall(function(creds, teamToken) { const onLoggedIn = jest.fn(function(creds, teamToken) {
expect(teamToken).toNotExist(); expect(teamToken).toBeFalsy();
done(); done();
}); });

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const jest = require('jest-mock');
const React = require('react'); const React = require('react');
const ReactDOM = require("react-dom"); const ReactDOM = require("react-dom");
const ReactTestUtils = require('react-addons-test-utils'); const ReactTestUtils = require('react-addons-test-utils');
@ -55,14 +56,14 @@ function doInputEmail(inputEmail, onTeamSelected) {
} }
function expectTeamSelectedFromEmailInput(inputEmail, expectedTeam) { function expectTeamSelectedFromEmailInput(inputEmail, expectedTeam) {
const onTeamSelected = expect.createSpy(); const onTeamSelected = jest.fn();
doInputEmail(inputEmail, onTeamSelected); doInputEmail(inputEmail, onTeamSelected);
expect(onTeamSelected).toHaveBeenCalledWith(expectedTeam); expect(onTeamSelected).toHaveBeenCalledWith(expectedTeam);
} }
function expectSupportFromEmailInput(inputEmail, isSupportShown) { function expectSupportFromEmailInput(inputEmail, isSupportShown) {
const onTeamSelected = expect.createSpy(); const onTeamSelected = jest.fn();
const res = doInputEmail(inputEmail, onTeamSelected); const res = doInputEmail(inputEmail, onTeamSelected);
expect(res.state.showSupportEmail).toBe(isSupportShown); expect(res.state.showSupportEmail).toBe(isSupportShown);

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import ReactTestUtils from 'react-addons-test-utils'; import ReactTestUtils from 'react-addons-test-utils';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import expect, {createSpy} from 'expect'; import expect from 'expect';
import sinon from 'sinon'; import sinon from 'sinon';
import Promise from 'bluebird'; import Promise from 'bluebird';
import * as testUtils from '../../../test-utils'; import * as testUtils from '../../../test-utils';

View File

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import expect, {createSpy} from 'expect'; import expect from 'expect';
import jest from 'jest-mock';
import Promise from 'bluebird'; import Promise from 'bluebird';
import * as testUtils from '../../../test-utils'; import * as testUtils from '../../../test-utils';
import sdk from 'matrix-react-sdk'; import sdk from 'matrix-react-sdk';
@ -18,12 +19,12 @@ describe('RoomSettings', () => {
function expectSentStateEvent(roomId, eventType, expectedEventContent) { function expectSentStateEvent(roomId, eventType, expectedEventContent) {
let found = false; let found = false;
for (const call of client.sendStateEvent.calls) { for (const call of client.sendStateEvent.mock.calls) {
const [ const [
actualRoomId, actualRoomId,
actualEventType, actualEventType,
actualEventContent, actualEventContent,
] = call.arguments.slice(0, 3); ] = call.slice(0, 3);
if (roomId === actualRoomId && actualEventType === eventType) { if (roomId === actualRoomId && actualEventType === eventType) {
expect(actualEventContent).toEqual(expectedEventContent); expect(actualEventContent).toEqual(expectedEventContent);
@ -40,20 +41,20 @@ describe('RoomSettings', () => {
client = MatrixClientPeg.get(); client = MatrixClientPeg.get();
client.credentials = {userId: '@me:domain.com'}; client.credentials = {userId: '@me:domain.com'};
client.setRoomName = createSpy().andReturn(Promise.resolve()); client.setRoomName = jest.fn().mockReturnValue(Promise.resolve());
client.setRoomTopic = createSpy().andReturn(Promise.resolve()); client.setRoomTopic = jest.fn().mockReturnValue(Promise.resolve());
client.setRoomDirectoryVisibility = createSpy().andReturn(Promise.resolve()); client.setRoomDirectoryVisibility = jest.fn().mockReturnValue(Promise.resolve());
// Covers any room state event (e.g. name, avatar, topic) // Covers any room state event (e.g. name, avatar, topic)
client.sendStateEvent = createSpy().andReturn(Promise.resolve()); client.sendStateEvent = jest.fn().mockReturnValue(Promise.resolve());
// Covers room tagging // Covers room tagging
client.setRoomTag = createSpy().andReturn(Promise.resolve()); client.setRoomTag = jest.fn().mockReturnValue(Promise.resolve());
client.deleteRoomTag = createSpy().andReturn(Promise.resolve()); client.deleteRoomTag = jest.fn().mockReturnValue(Promise.resolve());
// Covers any setting in the SettingsStore // Covers any setting in the SettingsStore
// (including local client settings not stored via matrix) // (including local client settings not stored via matrix)
SettingsStore.setValue = createSpy().andReturn(Promise.resolve()); SettingsStore.setValue = jest.fn().mockReturnValue(Promise.resolve());
parentDiv = document.createElement('div'); parentDiv = document.createElement('div');
document.body.appendChild(parentDiv); document.body.appendChild(parentDiv);
@ -83,9 +84,9 @@ describe('RoomSettings', () => {
it('should not set when no setting is changed', (done) => { it('should not set when no setting is changed', (done) => {
roomSettings.save().then(() => { roomSettings.save().then(() => {
expect(client.sendStateEvent).toNotHaveBeenCalled(); expect(client.sendStateEvent).not.toHaveBeenCalled();
expect(client.setRoomTag).toNotHaveBeenCalled(); expect(client.setRoomTag).not.toHaveBeenCalled();
expect(client.deleteRoomTag).toNotHaveBeenCalled(); expect(client.deleteRoomTag).not.toHaveBeenCalled();
done(); done();
}); });
}); });
@ -93,7 +94,7 @@ describe('RoomSettings', () => {
// XXX: Apparently we do call SettingsStore.setValue // XXX: Apparently we do call SettingsStore.setValue
xit('should not settings via the SettingsStore when no setting is changed', (done) => { xit('should not settings via the SettingsStore when no setting is changed', (done) => {
roomSettings.save().then(() => { roomSettings.save().then(() => {
expect(SettingsStore.setValue).toNotHaveBeenCalled(); expect(SettingsStore.setValue).not.toHaveBeenCalled();
done(); done();
}); });
}); });
@ -103,7 +104,7 @@ describe('RoomSettings', () => {
roomSettings.setName(name); roomSettings.setName(name);
roomSettings.save().then(() => { roomSettings.save().then(() => {
expect(client.setRoomName.calls[0].arguments.slice(0, 2)) expect(client.setRoomName.mock.calls[0].slice(0, 2))
.toEqual(['!DdJkzRliezrwpNebLk:matrix.org', name]); .toEqual(['!DdJkzRliezrwpNebLk:matrix.org', name]);
done(); done();
@ -115,7 +116,7 @@ describe('RoomSettings', () => {
roomSettings.setTopic(topic); roomSettings.setTopic(topic);
roomSettings.save().then(() => { roomSettings.save().then(() => {
expect(client.setRoomTopic.calls[0].arguments.slice(0, 2)) expect(client.setRoomTopic.mock.calls[0].slice(0, 2))
.toEqual(['!DdJkzRliezrwpNebLk:matrix.org', topic]); .toEqual(['!DdJkzRliezrwpNebLk:matrix.org', topic]);
done(); done();