From f2bf3f74cdb385bdd27cb5d5f5bf2f0f81c7718e Mon Sep 17 00:00:00 2001 From: Lawrence Wakefield Date: Fri, 23 Jun 2017 10:02:33 -0400 Subject: [PATCH 1/2] Cleans up warnings when testing --- package.json | 2 +- test/actions_test.js | 2 +- test/component_test.js | 57 ++++++++++++---------------- test/wrap_test.js | 86 +++++++++++------------------------------- 4 files changed, 49 insertions(+), 98 deletions(-) diff --git a/package.json b/package.json index 39e3cd2..16873f0 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "jest": "~19.0.1", "publish": "^0.6.0", "react": "^15.5.4", - "react-addons-test-utils": "~15.5.1", + "react-dom/test-utils": "~15.5.1", "react-dom": "^15.5.4", "webpack": "^2.2.1" }, diff --git a/test/actions_test.js b/test/actions_test.js index 3cf3e79..42db2ce 100644 --- a/test/actions_test.js +++ b/test/actions_test.js @@ -1,6 +1,6 @@ import React from 'react' import {fromJS} from 'immutable' -import TestUtils from 'react-addons-test-utils' +import TestUtils from 'react-dom/test-utils' import Tide from 'base' import TideComponent from 'component' import Actions, {initActions} from 'actions' diff --git a/test/component_test.js b/test/component_test.js index 1fb1d40..05ad1ce 100644 --- a/test/component_test.js +++ b/test/component_test.js @@ -1,6 +1,6 @@ /* eslint-disable react/no-multi-comp, react/display-name */ import React from 'react' -import TestUtils from 'react-addons-test-utils' +import TestUtils from 'react-dom/test-utils' import PropTypes from 'prop-types' import Immutable from 'immutable' @@ -14,27 +14,26 @@ describe('Component', function() { tideInstance = new Tide() }) - const createComponent = (render) => (props) => { - return React.createElement(React.createClass({ + const createComponent = (render) => (propsToInject) => { + class C extends React.Component { render() { - this.props = {...this.props, ...props} + this.props = {...this.props, ...propsToInject} render.apply(this) return null } - })) + } + return React.createElement(C) } describe('Context', function() { it('passes down the given tide instance in the context', function() { - const Child = React.createClass({ - contextTypes: { - tide: PropTypes.object - }, + class Child extends React.Component { + static contextTypes = {tide: PropTypes.object} render() { expect(this.context.tide).toBe(tideInstance) return null } - }) + } const tree = React.createElement(Component, {tide: tideInstance}, ({tide, ...props}) => React.createElement('div', props, @@ -49,16 +48,14 @@ describe('Component', function() { it( 'uses tide from context instead of props when directly nesting multiple components', function() { - const Child = React.createClass({ - contextTypes: { - tide: PropTypes.object - }, + class Child extends React.Component { + static contextTypes = {tide: PropTypes.object} render() { expect(this.context.tide).toBe(tideInstance) return null } - }) + } const tree = React.createElement(Component, {tide: tideInstance}, (props) => React.createElement(Component, {}, @@ -236,28 +233,24 @@ describe('Component', function() { it('does not re-render if something outside of the listened state updates', function(done) { const childRenderSpy = jest.fn() - const Child = React.createClass({ - render() { - childRenderSpy() - return null - } - }) + function Child () { + childRenderSpy() + return null + } let parentSetState = null - const Parent = React.createClass({ - getInitialState() { - return {foo: 'foo'} - }, + class Parent extends React.Component { + state = {foo: 'foo'} componentDidMount() { parentSetState = this.setState.bind(this) - }, + } render() { const child = React.createElement(Child, this.state) return React.createElement(Component, {tide: tideInstance}, () => child) } - }) + } TestUtils.renderIntoDocument(React.createElement(Parent)) @@ -274,19 +267,17 @@ describe('Component', function() { tideInstance.setState(Immutable.Map({foo: 'foo', bar: 'bar'})) let parentSetState = null - const Parent = React.createClass({ - getInitialState() { - return {foo: 'foo'} - }, + class Parent extends React.Component { + state = {foo: 'foo'} componentDidMount() { parentSetState = this.setState.bind(this) - }, + } render() { return React.createElement(Component, {tide: tideInstance, impure: true}, Child) } - }) + } expect(spy).toHaveBeenCalledTimes(0) TestUtils.renderIntoDocument(React.createElement(Parent)) diff --git a/test/wrap_test.js b/test/wrap_test.js index 0de4bc1..e7089aa 100644 --- a/test/wrap_test.js +++ b/test/wrap_test.js @@ -1,7 +1,7 @@ /* eslint-disable react/no-multi-comp */ import React from 'react' import Immutable from 'immutable' -import TestUtils from 'react-addons-test-utils' +import TestUtils from 'react-dom/test-utils' import Tide from 'base' import wrap from 'wrap' @@ -9,8 +9,10 @@ import wrap from 'wrap' let tideInstance describe('wrap', function() { + let parentSetState beforeEach(function() { tideInstance = new Tide() + parentSetState = null }) function createWrappedComponent(tideInstance, renderSpy, tideProps = {}, mappers) { @@ -24,6 +26,18 @@ describe('wrap', function() { return wrap(Child, {tide: tideInstance, ...tideProps}, mappers) } + function getParent(Wrapped) { + return class Parent extends React.Component { + state = {childProp: 'bar'} + componentDidMount() { + parentSetState = this.setState.bind(this) + } + render() { + return React.createElement(Wrapped, this.state) + } + } + } + it('wraps the given component class with a tide component', function() { const spy = jest.fn() @@ -65,27 +79,13 @@ describe('wrap', function() { const Wrapped = createWrappedComponent(tideInstance, function() { return spy(this.props.childProp) }) - - let parentSetState = null - const Parent = React.createClass({ - getInitialState() { - return {childProp: 'foo'} - }, - - componentDidMount() { - parentSetState = this.setState.bind(this) - }, - - render() { - return React.createElement(Wrapped, this.state) - } - }) + const Parent = getParent(Wrapped) TestUtils.renderIntoDocument(React.createElement(Parent)) - expect(spy).toHaveBeenCalledWith('foo') - parentSetState({childProp: 'bar'}) expect(spy).toHaveBeenCalledWith('bar') + parentSetState({childProp: 'foo'}) + expect(spy).toHaveBeenCalledWith('foo') }) it('does not re-render the child when given the same props', function(done) { @@ -94,26 +94,12 @@ describe('wrap', function() { const Wrapped = createWrappedComponent(tideInstance, function() { return spy(this.props.childProp) }) - - let parentSetState = null - const Parent = React.createClass({ - getInitialState() { - return {childProp: 'foo'} - }, - - componentDidMount() { - parentSetState = this.setState.bind(this) - }, - - render() { - return React.createElement(Wrapped, this.state) - } - }) + const Parent = getParent(Wrapped) TestUtils.renderIntoDocument(React.createElement(Parent)) expect(spy).toHaveBeenCalledTimes(1) - parentSetState({childProp: 'foo'}, () => { + parentSetState({childProp: 'bar'}, () => { expect(spy).toHaveBeenCalledTimes(1) done() }) @@ -126,21 +112,8 @@ describe('wrap', function() { return spy(this.props.childProp) } , {impure: true}) + const Parent = getParent(Wrapped) - let parentSetState = null - const Parent = React.createClass({ - getInitialState() { - return {childProp: 'foo'} - }, - - componentDidMount() { - parentSetState = this.setState.bind(this) - }, - - render() { - return React.createElement(Wrapped, this.state) - } - }) TestUtils.renderIntoDocument(React.createElement(Parent)) expect(spy).toHaveBeenCalledTimes(1) parentSetState({childProp: 'foo'}, () => { @@ -159,21 +132,7 @@ describe('wrap', function() { }, {foo: 'foo', bar: 'bar'}, { foo: (val) => 'mapped_' + val, }) - - let parentSetState = null - const Parent = React.createClass({ - getInitialState() { - return {childProp: 'bar'} - }, - - componentDidMount() { - parentSetState = this.setState.bind(this) - }, - - render() { - return React.createElement(Wrapped, this.state) - } - }) + const Parent = getParent(Wrapped) TestUtils.renderIntoDocument(React.createElement(Parent)) @@ -195,3 +154,4 @@ describe('wrap', function() { }) }) }) + From cdc79c7f938a023183718a1f04b5f26a6d35bee4 Mon Sep 17 00:00:00 2001 From: Lawrence Wakefield Date: Fri, 23 Jun 2017 11:33:31 -0400 Subject: [PATCH 2/2] Remove broken package --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 16873f0..4dc309b 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "jest": "~19.0.1", "publish": "^0.6.0", "react": "^15.5.4", - "react-dom/test-utils": "~15.5.1", "react-dom": "^15.5.4", "webpack": "^2.2.1" },