Skip to content

Commit

Permalink
upgrade JSDOM to 15.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
erikphansen committed May 18, 2020
1 parent 2505680 commit 08ce1ef
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 113 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"isomorphic-fetch": "^2.2.1",
"jest": "^23.6.0",
"jest-image-snapshot": "^2.7.0",
"jsdom": "^11.1.0",
"jsdom": "^15.2.1",
"json2csv": "^4.2.1",
"jsonschema": "^1.1.1",
"libxmljs": "^0.19.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ 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 @@ -30,14 +32,20 @@ describe('<MhvTermsAndConditions>', () => {
};

const setup = () => {
global.window.location.replace = sinon.spy();
oldLocation = global.window.location;
delete global.window.location;
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: 4 additions & 3 deletions src/applications/vaos/tests/containers/VAOSApp.unit.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ describe('VAOS <VAOSApp>', () => {
},
};

const oldReplace = window.location.replace;
window.location.replace = sinon.spy();
const oldLocation = window.location;
delete window.location;
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 = oldReplace;
window.location.replace = oldLocation;
tree.unmount();
});
});
18 changes: 16 additions & 2 deletions src/platform/testing/unit/mocha-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export default function setupJSDom() {
/* eslint-enable no-console */

// setup the simplest document possible
const dom = new JSDOM('<!doctype html><html><body></body></html>');
const dom = new JSDOM('<!doctype html><html><body></body></html>', {
url: 'http://localhost',
});

// get the window object out of the document
const win = dom.window;
Expand Down Expand Up @@ -63,7 +65,19 @@ export default function setupJSDom() {

win.dataLayer = [];
win.scrollTo = () => {};
win.sessionStorage = {};
// win.sessionStorage = {};
Object.defineProperty(win, 'sessionStorage', {
value: global.sessionStorage,
configurable: true,
enumerable: true,
writable: true,
});
Object.defineProperty(win, 'localStorage', {
value: global.localStorage,
configurable: true,
enumerable: true,
writable: true,
});
win.requestAnimationFrame = func => func();
win.matchMedia = () => ({
matches: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import backendServices from '../../../../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 @@ -28,7 +30,11 @@ describe('<MHVApp>', () => {
};

const setup = () => {
global.window.location.replace = sinon.spy();
oldLocation = global.window.location;
delete global.window.location;
global.window.location = {
replace: sinon.spy(),
};
props.createMHVAccount.reset();
props.fetchMHVAccount.reset();
props.upgradeMHVAccount.reset();
Expand All @@ -52,6 +58,10 @@ 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
Loading

0 comments on commit 08ce1ef

Please sign in to comment.