Skip to content

Commit

Permalink
stop using global variables in enzyme test
Browse files Browse the repository at this point in the history
(except for the dom ones that are necessary)

enzymejs/enzyme#341
  • Loading branch information
alex committed Nov 30, 2017
1 parent 97742e6 commit a773336
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions tests/saved-coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
Enzyme.configure({ adapter: new Adapter() });

const jsdom = require('jsdom');
const dom = new jsdom.JSDOM('<!doctype html><html><body></body></html>');
global.document = dom.window.document;
global.window = dom.window;

const mount = require('enzyme').mount;

// for now let's use the same set-up and just pass in the global variables
// some of it will be redundant (like the dom)
require('./helpers/integration-global');
const integrationHelper = require('./helpers/integration-helper');

const Sut = require('../src/clock-app');

Expand All @@ -22,20 +25,16 @@ const LONGITUDE = 55;
expect(EXPECTED_COORDINATE_STRING).to.include(LATITUDE);
expect(EXPECTED_COORDINATE_STRING).to.include(LONGITUDE);

global.testVars.storedCoordinates = JSON.stringify({
integrationHelper.testVars.storedCoordinates = JSON.stringify({
latitude: LATITUDE,
longitude: LONGITUDE,
});

const wrapper = mount(<Sut
geolocation={navigator.geolocation}
localStorage={localStorage}
setInterval={setInterval}
/>);
const wrapper = mount(<Sut {...integrationHelper.props} />);

expect(global.testVars.timerCallback).to.be.a('function');
expect(global.testVars.timerInterval).to.equal(10000);
expect(global.testVars.storedCoordinates).to.be.ok;
expect(integrationHelper.testVars.timerCallback).to.be.a('function');
expect(integrationHelper.testVars.timerInterval).to.equal(10000);
expect(integrationHelper.testVars.storedCoordinates).to.be.ok;

expect(wrapper.html()).to.include('face.svg');
expect(wrapper.html()).to.include(EXPECTED_COORDINATE_STRING);

0 comments on commit a773336

Please sign in to comment.