summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-07-24 15:52:20 +0100
committerAndrej Mihajlov <and@mullvad.net>2017-07-27 09:11:38 +0100
commitc206f43bbcbd08c210e850a92a09c7fc5fea9394 (patch)
tree9e7482891a7eb6b39ec0e8272ad713a28f6d7149 /test
parent1243076c3c8c824a99a230d008ee456ee1ed0b30 (diff)
downloadmullvadvpn-c206f43bbcbd08c210e850a92a09c7fc5fea9394.tar.xz
mullvadvpn-c206f43bbcbd08c210e850a92a09c7fc5fea9394.zip
Remove JSDOM and update Switch component
Diffstat (limited to 'test')
-rw-r--r--test/components/Switch.spec.js36
-rw-r--r--test/global.js18
-rw-r--r--test/setup/main.js4
3 files changed, 35 insertions, 23 deletions
diff --git a/test/components/Switch.spec.js b/test/components/Switch.spec.js
index 8cdc053c24..db7fe8d8c4 100644
--- a/test/components/Switch.spec.js
+++ b/test/components/Switch.spec.js
@@ -2,17 +2,43 @@
import { expect } from 'chai';
import React from 'react';
+import ReactDOM from 'react-dom';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import Switch from '../../app/components/Switch';
describe('components/Switch', () => {
+ let container: ?HTMLElement;
+
+ function renderIntoDocument(instance: React.Element<*>): React.Component<*, *, *> {
+ if(container) {
+ throw new Error('Unmount previously rendered component first.');
+ }
+
+ container = document.createElement('div');
+ if(!document.documentElement) {
+ throw new Error('document.documentElement cannot be null.');
+ }
+
+ document.documentElement.appendChild(container);
+
+ return ReactDOM.render(instance, container);
+ }
+
+ // unmount container and clean up DOM
+ afterEach(() => {
+ if(container) {
+ ReactDOM.unmountComponentAtNode(container);
+ container = null;
+ }
+ });
+
it('should switch on', (done) => {
const onChange = (isOn) => {
expect(isOn).to.be.true;
done();
};
- const component = ReactTestUtils.renderIntoDocument(
+ const component = renderIntoDocument(
<Switch isOn={ false } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
@@ -27,7 +53,7 @@ describe('components/Switch', () => {
expect(isOn).to.be.false;
done();
};
- const component = ReactTestUtils.renderIntoDocument(
+ const component = renderIntoDocument(
<Switch isOn={ true } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
@@ -42,7 +68,7 @@ describe('components/Switch', () => {
expect(isOn).to.be.true;
done();
};
- const component = ReactTestUtils.renderIntoDocument(
+ const component = renderIntoDocument(
<Switch isOn={ false } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
@@ -59,7 +85,7 @@ describe('components/Switch', () => {
expect(isOn).to.be.false;
done();
};
- const component = ReactTestUtils.renderIntoDocument(
+ const component = renderIntoDocument(
<Switch isOn={ true } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
@@ -76,7 +102,7 @@ describe('components/Switch', () => {
throw new Error('onChange should not be called on timeout.');
};
- const component = ReactTestUtils.renderIntoDocument(
+ const component = renderIntoDocument(
<Switch isOn={ false } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
diff --git a/test/global.js b/test/global.js
deleted file mode 100644
index 7b4af72b63..0000000000
--- a/test/global.js
+++ /dev/null
@@ -1,18 +0,0 @@
-import log from 'electron-log';
-import { JSDOM } from 'jsdom';
-
-before(() => {
- log.transports.console.level = false;
- log.transports.file.level = false;
-});
-
-beforeEach(() => {
- const dom = new JSDOM('<!doctype html><html><body></body></html>');
- const window = dom.window;
- global.window = window;
- global.document = window.document;
- global.navigator = window.navigator;
- global.HTMLInputElement = window.HTMLInputElement;
- global.Event = window.Event;
- global.MouseEvent = window.MouseEvent;
-});
diff --git a/test/setup/main.js b/test/setup/main.js
new file mode 100644
index 0000000000..dd458a30b6
--- /dev/null
+++ b/test/setup/main.js
@@ -0,0 +1,4 @@
+const log = require('electron-log');
+
+log.transports.console.level = false;
+log.transports.file.level = false;