summaryrefslogtreecommitdiffhomepage
path: root/test/components
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/components
parent1243076c3c8c824a99a230d008ee456ee1ed0b30 (diff)
downloadmullvadvpn-c206f43bbcbd08c210e850a92a09c7fc5fea9394.tar.xz
mullvadvpn-c206f43bbcbd08c210e850a92a09c7fc5fea9394.zip
Remove JSDOM and update Switch component
Diffstat (limited to 'test/components')
-rw-r--r--test/components/Switch.spec.js36
1 files changed, 31 insertions, 5 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');