Skip to content

Commit

Permalink
better (?) mocha setup
Browse files Browse the repository at this point in the history
  • Loading branch information
erikphansen committed May 19, 2020
1 parent a100b1a commit cdad817
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import sinon from 'sinon';
import { MhvTermsAndConditions } from '../../containers/MhvTermsAndConditions';

describe('<MhvTermsAndConditions>', () => {
let oldLocation;

const props = {
location: {
pathname: '/health-care/medical-information-terms-conditions',
Expand All @@ -32,20 +30,14 @@ describe('<MhvTermsAndConditions>', () => {
};

const setup = () => {
oldLocation = global.window.location;
delete global.window.location;
global.window.location = { replace: sinon.spy() };
global.window.location.replace = sinon.spy();
props.acceptTerms.reset();
props.fetchLatestTerms.reset();
props.fetchTermsAcceptance.reset();
};

beforeEach(setup);

afterEach(() => {
global.window.location = oldLocation;
});

it('should show an error when there are errors', () => {
const newProps = set('errors', { code: 404 }, props);
const wrapper = shallow(<MhvTermsAndConditions {...newProps} />);
Expand Down
7 changes: 3 additions & 4 deletions src/applications/vaos/tests/containers/VAOSApp.unit.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,14 @@ describe('VAOS <VAOSApp>', () => {
},
};

const oldLocation = window.location;
delete window.location;
window.location = { replace: sinon.spy() };
const oldReplace = window.location.replace;
window.location.replace = sinon.spy();
const tree = mount(<VAOSApp showApplication user={user} />);

expect(window.location.replace.firstCall.args[0]).to.contain('verify');
expect(tree.find('RequiredLoginView').exists()).to.be.true;

window.location.replace = oldLocation;
window.location.replace = oldReplace;
tree.unmount();
});
});
13 changes: 5 additions & 8 deletions src/platform/testing/unit/mocha-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,13 @@ export default function setupJSDom() {

win.dataLayer = [];
win.scrollTo = () => {};
Object.defineProperty(win, 'sessionStorage', {
value: global.sessionStorage,
configurable: true,
enumerable: true,
Object.defineProperty(win, 'localStorage', {
writable: true,
});
Object.defineProperty(win, 'localStorage', {
value: global.localStorage,
configurable: true,
enumerable: true,
Object.defineProperty(win.location, 'replace', {
writable: true,
});
Object.defineProperty(win, 'sessionStorage', {
writable: true,
});
win.requestAnimationFrame = func => func();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { shallow } from 'enzyme';
import { merge, set } from 'lodash/fp';
import sinon from 'sinon';

import backendServices from '../../../../user/profile/constants/backendServices';
import backendServices from 'platform/user/profile/constants/backendServices';
import { MHVApp } from '../../../authorization/containers/MHVApp';

describe('<MHVApp>', () => {
let oldLocation;

const props = {
location: { pathname: '/health-care/prescriptions', query: {} },
mhvAccount: {
Expand All @@ -30,11 +28,7 @@ describe('<MHVApp>', () => {
};

const setup = () => {
oldLocation = global.window.location;
delete global.window.location;
global.window.location = {
replace: sinon.spy(),
};
global.window.location.replace = sinon.spy();
props.createMHVAccount.reset();
props.fetchMHVAccount.reset();
props.upgradeMHVAccount.reset();
Expand All @@ -58,10 +52,6 @@ describe('<MHVApp>', () => {

beforeEach(setup);

afterEach(() => {
global.window.location = oldLocation;
});

it('should show a loading indicator when fetching an account', () => {
const newProps = set('mhvAccount.loading', true, props);
const wrapper = shallow(<MHVApp {...newProps} />, { context });
Expand Down

0 comments on commit cdad817

Please sign in to comment.