diff --git a/test-runner.js b/test-runner.js
index 8734926bbb2..8a54abc433d 100644
--- a/test-runner.js
+++ b/test-runner.js
@@ -1,4 +1,5 @@
require('babel-polyfill');
+require('tests/client/init');
const testsContext = require.context('./tests/client/', true, /\.js$/);
const componentsContext = require.context(
diff --git a/tests/client/core/api/test_api.js b/tests/client/core/api/test_api.js
index 34947415c45..74c437547e4 100644
--- a/tests/client/core/api/test_api.js
+++ b/tests/client/core/api/test_api.js
@@ -7,10 +7,6 @@ describe('api', () => {
mockWindow = sinon.mock(window);
});
- afterEach(() => {
- mockWindow.restore();
- });
-
describe('search api', () => {
function mockResponse() {
return Promise.resolve({
diff --git a/tests/client/core/containers/TestHandleLogin.js b/tests/client/core/containers/TestHandleLogin.js
index f831ee77edd..7876535dfdf 100644
--- a/tests/client/core/containers/TestHandleLogin.js
+++ b/tests/client/core/containers/TestHandleLogin.js
@@ -8,16 +8,6 @@ import HandleLogin, { mapDispatchToProps } from 'core/containers/HandleLogin';
import * as api from 'core/api';
describe('', () => {
- let sandbox;
-
- beforeEach(() => {
- sandbox = sinon.sandbox.create();
- });
-
- afterEach(() => {
- sandbox.restore();
- });
-
class MyRouter extends React.Component {
static propTypes = {
children: React.PropTypes.node.isRequired,
@@ -56,12 +46,12 @@ describe('', () => {
let router;
beforeEach(() => {
- mockApi = sandbox.mock(api);
+ mockApi = sinon.mock(api);
mockApi
.expects('login')
.withArgs({api: {}, code, state})
.returns(Promise.resolve());
- router = sandbox.mock({push: () => {}});
+ router = sinon.mock({push: () => {}});
});
it('notifies the user that they are being logged in', () => {
@@ -82,8 +72,8 @@ describe('', () => {
let mockApi;
beforeEach(() => {
- router = sandbox.mock({});
- mockApi = sandbox.mock(api);
+ router = sinon.mock({});
+ mockApi = sinon.mock(api);
mockApi.expects('login').never();
});
@@ -111,14 +101,14 @@ describe('', () => {
function setupData() {
const data = {
apiConfig: {},
- dispatch: sandbox.stub(),
+ dispatch: sinon.stub(),
router: {push: () => {}},
code: 'acodefromfxa',
state: 'thestatefromamo',
payload: {token: 'sometoken'},
};
data.location = {query: {code: data.code, state: data.state}};
- sandbox.stub(api, 'login').withArgs({
+ sinon.stub(api, 'login').withArgs({
api: data.apiConfig,
code: data.code,
state: data.state,
@@ -138,7 +128,7 @@ describe('', () => {
it('stores the token in a cookie', () => {
const { apiConfig, dispatch, location, payload: {token}, router } = setupData();
const { loadData } = mapDispatchToProps(dispatch);
- const mockCookie = sandbox.mock(cookie);
+ const mockCookie = sinon.mock(cookie);
mockCookie.expects('save').once().withArgs(
'jwt_api_auth_token', token, {path: '/', secure: true, maxAge: 2592000});
return loadData({api: apiConfig, location, router}).then(() => {
@@ -149,7 +139,7 @@ describe('', () => {
it('redirects to the search endpoint', () => {
const { apiConfig, dispatch, location, router } = setupData();
const { loadData } = mapDispatchToProps(dispatch);
- const mockRouter = sandbox.mock(router);
+ const mockRouter = sinon.mock(router);
mockRouter
.expects('push')
.once()
diff --git a/tests/client/disco/TestAddonManager.js b/tests/client/disco/TestAddonManager.js
index 80d00ec18a3..c80f1cec3e5 100644
--- a/tests/client/disco/TestAddonManager.js
+++ b/tests/client/disco/TestAddonManager.js
@@ -8,30 +8,24 @@ describe('AddonManager', () => {
let fakeInstallObj;
let fakeInstallUrl;
let fakeMozAddonManager;
- let sandbox;
beforeEach(() => {
- sandbox = sinon.sandbox.create();
- fakeCallback = sandbox.stub();
+ fakeCallback = sinon.stub();
fakeInstallUrl = 'https://fake-install-url';
fakeAddon = {
- uninstall: sandbox.stub(),
+ uninstall: sinon.stub(),
};
fakeInstallObj = {
- addEventListener: sandbox.stub(),
- install: sandbox.stub(),
+ addEventListener: sinon.stub(),
+ install: sinon.stub(),
};
fakeMozAddonManager = {
- createInstall: sandbox.stub(),
- getAddonByID: sandbox.stub(),
+ createInstall: sinon.stub(),
+ getAddonByID: sinon.stub(),
};
fakeMozAddonManager.createInstall.returns(Promise.resolve(fakeInstallObj));
});
- afterEach(() => {
- sandbox.restore();
- });
-
it('should throw if mozAddonManager is not provided', () => {
assert.throws(() => {
// eslint-disable-next-line no-unused-vars
diff --git a/tests/client/init.js b/tests/client/init.js
new file mode 100644
index 00000000000..0761bbb4874
--- /dev/null
+++ b/tests/client/init.js
@@ -0,0 +1,10 @@
+const realSinon = sinon;
+
+beforeEach(() => {
+ window.sinon = realSinon.sandbox.create();
+});
+
+afterEach(() => {
+ window.sinon.restore();
+ window.sinon = realSinon;
+});
diff --git a/tests/client/search/TestUserPage.js b/tests/client/search/TestUserPage.js
index 8c5647233d1..be5a06a6dae 100644
--- a/tests/client/search/TestUserPage.js
+++ b/tests/client/search/TestUserPage.js
@@ -23,23 +23,17 @@ describe('', () => {
});
describe('loadProfileIfNeeded', () => {
- let sandbox;
let mockApi;
beforeEach(() => {
- sandbox = sinon.sandbox.create();
- mockApi = sandbox.mock(api);
- });
-
- afterEach(() => {
- sandbox.restore();
+ mockApi = sinon.mock(api);
});
it('loads the profile when it is not loaded', () => {
const apiConfig = {api: 'config'};
const entities = {'the-username': {username: 'the-username'}};
const result = 'the-username';
- const dispatch = sandbox.stub();
+ const dispatch = sinon.stub();
const store = {
dispatch,
getState() {
@@ -63,7 +57,7 @@ describe('', () => {
it('does not load the profile when it is loaded', () => {
const apiConfig = {api: 'config'};
- const dispatch = sandbox.stub();
+ const dispatch = sinon.stub();
const store = {
dispatch,
getState() {
diff --git a/tests/client/search/containers/TestAddonPage.js b/tests/client/search/containers/TestAddonPage.js
index cc76abd49c5..6048704d12b 100644
--- a/tests/client/search/containers/TestAddonPage.js
+++ b/tests/client/search/containers/TestAddonPage.js
@@ -212,24 +212,12 @@ describe('AddonPage', () => {
const loadedSlug = 'my-addon';
let loadedAddon;
let dispatch;
- let mocks;
beforeEach(() => {
loadedAddon = sinon.stub();
dispatch = sinon.spy();
- mocks = [];
});
- afterEach(() => {
- mocks.forEach((mock) => mock.restore());
- });
-
- function makeMock(thing) {
- const mock = sinon.mock(thing);
- mocks.push(mock);
- return mock;
- }
-
function makeProps(slug) {
return {
store: {
@@ -254,14 +242,14 @@ describe('AddonPage', () => {
const props = makeProps(slug, apiState);
const addon = sinon.stub();
const entities = {[slug]: addon};
- const mockApi = makeMock(api);
+ const mockApi = sinon.mock(api);
mockApi
.expects('fetchAddon')
.once()
.withArgs({slug, api: apiState})
.returns(Promise.resolve({entities}));
const action = sinon.stub();
- const mockActions = makeMock(actions);
+ const mockActions = sinon.mock(actions);
mockActions
.expects('loadEntities')
.once()
@@ -277,13 +265,13 @@ describe('AddonPage', () => {
it('handles 404s when loading the add-on', () => {
const slug = 'other-addon';
const props = makeProps(slug, apiState);
- const mockApi = makeMock(api);
+ const mockApi = sinon.mock(api);
mockApi
.expects('fetchAddon')
.once()
.withArgs({slug, api: apiState})
.returns(Promise.reject(new Error('Error accessing API')));
- const mockActions = makeMock(actions);
+ const mockActions = sinon.mock(actions);
mockActions
.expects('loadEntities')
.never();