Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test-runner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('babel-polyfill');
require('tests/client/init');

const testsContext = require.context('./tests/client/', true, /\.js$/);
const componentsContext = require.context(
Expand Down
4 changes: 0 additions & 4 deletions tests/client/core/api/test_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ describe('api', () => {
mockWindow = sinon.mock(window);
});

afterEach(() => {
mockWindow.restore();
});

describe('search api', () => {
function mockResponse() {
return Promise.resolve({
Expand Down
26 changes: 8 additions & 18 deletions tests/client/core/containers/TestHandleLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ import HandleLogin, { mapDispatchToProps } from 'core/containers/HandleLogin';
import * as api from 'core/api';

describe('<HandleLogin />', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
});

afterEach(() => {
sandbox.restore();
});

class MyRouter extends React.Component {
static propTypes = {
children: React.PropTypes.node.isRequired,
Expand Down Expand Up @@ -56,12 +46,12 @@ describe('<HandleLogin />', () => {
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', () => {
Expand All @@ -82,8 +72,8 @@ describe('<HandleLogin />', () => {
let mockApi;

beforeEach(() => {
router = sandbox.mock({});
mockApi = sandbox.mock(api);
router = sinon.mock({});
mockApi = sinon.mock(api);
mockApi.expects('login').never();
});

Expand Down Expand Up @@ -111,14 +101,14 @@ describe('<HandleLogin />', () => {
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,
Expand All @@ -138,7 +128,7 @@ describe('<HandleLogin />', () => {
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(() => {
Expand All @@ -149,7 +139,7 @@ describe('<HandleLogin />', () => {
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()
Expand Down
18 changes: 6 additions & 12 deletions tests/client/disco/TestAddonManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/client/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const realSinon = sinon;

beforeEach(() => {
window.sinon = realSinon.sandbox.create();
});

afterEach(() => {
window.sinon.restore();
window.sinon = realSinon;
});
12 changes: 3 additions & 9 deletions tests/client/search/TestUserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,17 @@ describe('<UserPage />', () => {
});

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() {
Expand All @@ -63,7 +57,7 @@ describe('<UserPage />', () => {

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() {
Expand Down
20 changes: 4 additions & 16 deletions tests/client/search/containers/TestAddonPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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()
Expand All @@ -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();
Expand Down