summaryrefslogtreecommitdiffhomepage
path: root/test/components
diff options
context:
space:
mode:
Diffstat (limited to 'test/components')
-rw-r--r--test/components/Accordion.spec.js6
-rw-r--r--test/components/AccountInput.spec.js10
-rw-r--r--test/components/SelectLocation.spec.js9
-rw-r--r--test/components/Switch.spec.js49
4 files changed, 47 insertions, 27 deletions
diff --git a/test/components/Accordion.spec.js b/test/components/Accordion.spec.js
index 2357e27dfc..1ef4d2871e 100644
--- a/test/components/Accordion.spec.js
+++ b/test/components/Accordion.spec.js
@@ -2,17 +2,15 @@
/* eslint react/no-find-dom-node: off */
import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import ReactDOM from 'react-dom';
import Accordion from '../../app/components/Accordion';
-import type { AccordionProps } from '../../app/components/Accordion';
-
describe('components/Accordion', () => {
let container: ?HTMLElement;
- function renderIntoDocument(instance: React.Element<AccordionProps>) {
+ function renderIntoDocument(instance) {
if(!container) {
container = document.createElement('div');
if(!document.documentElement) {
diff --git a/test/components/AccountInput.spec.js b/test/components/AccountInput.spec.js
index ee73323950..701a1c243e 100644
--- a/test/components/AccountInput.spec.js
+++ b/test/components/AccountInput.spec.js
@@ -1,15 +1,19 @@
// @flow
import { expect } from 'chai';
import { createKeyEvent } from '../helpers/dom-events';
-import React from 'react';
+import * as React from 'react';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import AccountInput from '../../app/components/AccountInput';
import type { AccountInputProps } from '../../app/components/AccountInput';
describe('components/AccountInput', () => {
- const getInputRef = (component: AccountInput): HTMLInputElement => {
- return ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
+ const getInputRef = (component) => {
+ const node = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
+ if(!(node instanceof HTMLInputElement)) {
+ throw new Error('Node is expected to be an instance of HTMLInputElement');
+ }
+ return node;
};
const render = (mergeProps: $Shape<AccountInputProps>) => {
diff --git a/test/components/SelectLocation.spec.js b/test/components/SelectLocation.spec.js
index eb72b03c57..59a8dc9770 100644
--- a/test/components/SelectLocation.spec.js
+++ b/test/components/SelectLocation.spec.js
@@ -1,7 +1,7 @@
// @flow
import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import SelectLocation from '../../app/components/SelectLocation';
@@ -47,7 +47,7 @@ describe('components/SelectLocation', () => {
return Object.assign({}, defaultProps, mergeProps);
};
- const render = (props: SelectLocationProps): SelectLocation => {
+ const render = (props: SelectLocationProps) => {
return ReactTestUtils.renderIntoDocument(
<SelectLocation { ...props } />
);
@@ -58,7 +58,10 @@ describe('components/SelectLocation', () => {
onClose: () => done()
});
const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'select-location__close');
- Simulate.click(domNode);
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.click(domNode);
+ }
});
it('should call select callback for country', (done) => {
diff --git a/test/components/Switch.spec.js b/test/components/Switch.spec.js
index db7fe8d8c4..eaac6dc08c 100644
--- a/test/components/Switch.spec.js
+++ b/test/components/Switch.spec.js
@@ -1,7 +1,7 @@
// @flow
import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import Switch from '../../app/components/Switch';
@@ -10,7 +10,7 @@ describe('components/Switch', () => {
let container: ?HTMLElement;
- function renderIntoDocument(instance: React.Element<*>): React.Component<*, *, *> {
+ function renderIntoDocument(instance: React.Element<*>): React.Component<*, *> {
if(container) {
throw new Error('Unmount previously rendered component first.');
}
@@ -42,10 +42,12 @@ describe('components/Switch', () => {
<Switch isOn={ false } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
-
- Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
- Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 });
- Simulate.change(domNode, { target: { checked: true } });
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 });
+ Simulate.change(domNode, { target: { checked: true } });
+ }
});
it('should switch off', (done) => {
@@ -57,10 +59,12 @@ describe('components/Switch', () => {
<Switch isOn={ true } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
-
- Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
- Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 });
- Simulate.change(domNode, { target: { checked: false } });
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 });
+ Simulate.change(domNode, { target: { checked: false } });
+ }
});
it('should handle left to right swipe', (done) => {
@@ -72,8 +76,10 @@ describe('components/Switch', () => {
<Switch isOn={ false } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
-
- Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ }
// Switch listens to events on document
document.dispatchEvent(new MouseEvent('mousemove', { clientX: 150, clientY: 0 }));
@@ -90,7 +96,10 @@ describe('components/Switch', () => {
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
- Simulate.mouseDown(domNode, { clientX: 150, clientY: 0 });
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 150, clientY: 0 });
+ }
// Switch listens to events on document
document.dispatchEvent(new MouseEvent('mousemove', { clientX: 100, clientY: 0 }));
@@ -105,17 +114,23 @@ describe('components/Switch', () => {
const component = renderIntoDocument(
<Switch isOn={ false } onChange={ onChange } />
);
- const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
- Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ }
setTimeout(() => {
// Switch listens to events on document
document.dispatchEvent(new MouseEvent('mouseup', { clientX: 100, clientY: 0 }));
try {
- // should not trigger onChange()
- Simulate.change(domNode);
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ // should not trigger onChange()
+ Simulate.change(domNode);
+ }
done();
} catch(e) {
done(e);