diff options
| -rw-r--r-- | test/components/Accordion.spec.js | 4 | ||||
| -rw-r--r-- | test/components/AccountInput.spec.js | 10 | ||||
| -rw-r--r-- | test/components/SelectLocation.spec.js | 9 | ||||
| -rw-r--r-- | test/components/Switch.spec.js | 44 |
4 files changed, 44 insertions, 23 deletions
diff --git a/test/components/Accordion.spec.js b/test/components/Accordion.spec.js index bd69c6a7b5..1ef4d2871e 100644 --- a/test/components/Accordion.spec.js +++ b/test/components/Accordion.spec.js @@ -2,7 +2,7 @@ /* 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'; @@ -10,7 +10,7 @@ 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 a369ba777c..eaac6dc08c 100644 --- a/test/components/Switch.spec.js +++ b/test/components/Switch.spec.js @@ -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 })); @@ -107,16 +116,21 @@ describe('components/Switch', () => { ); 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 }); + } 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); |
