Skip to content

Commit

Permalink
Should not rely on synchronous return value of renderIntoDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
jimfb authored and jim committed May 16, 2016
1 parent 6b1232a commit f424a99
Show file tree
Hide file tree
Showing 40 changed files with 407 additions and 373 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"plugins": [
"fbjs-scripts/babel-6/dev-expression",
"syntax-trailing-function-commas",
"babel-plugin-transform-async-to-generator",
"babel-plugin-transform-object-rest-spread",
"transform-es2015-template-literals",
"transform-es2015-literals",
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,9 @@
"unmockedModulePathPatterns": [
""
]
},
"dependencies": {
"babel-plugin-syntax-async-functions": "^6.8.0",
"babel-plugin-transform-async-to-generator": "^6.8.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ReactComponentWithPureRenderMixin', function() {
ReactTestUtils = require('ReactTestUtils');
});

it('provides a default shouldComponentUpdate implementation', function() {
pit('provides a default shouldComponentUpdate implementation', async function() {
var renderCalls = 0;
class PlasticWrap extends React.Component {
constructor(props, context) {
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('ReactComponentWithPureRenderMixin', function() {
},
});

var instance = ReactTestUtils.renderIntoDocument(<PlasticWrap />);
var instance = await ReactTestUtils.renderIntoDocumentAsync(<PlasticWrap />);
expect(renderCalls).toBe(1);

// Do not re-render based on props
Expand All @@ -97,7 +97,7 @@ describe('ReactComponentWithPureRenderMixin', function() {
expect(renderCalls).toBe(4);
});

it('does not do a deep comparison', function() {
pit('does not do a deep comparison', async function() {
function getInitialState() {
return {
foo: [1, 2, 3],
Expand All @@ -121,7 +121,7 @@ describe('ReactComponentWithPureRenderMixin', function() {
},
});

var instance = ReactTestUtils.renderIntoDocument(<Component />);
var instance = await ReactTestUtils.renderIntoDocumentAsync(<Component />);
expect(renderCalls).toBe(1);

// Do not re-render if state is equal
Expand Down
4 changes: 2 additions & 2 deletions src/addons/link/__tests__/LinkedStateMixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('LinkedStateMixin', function() {
ReactTestUtils = require('ReactTestUtils');
});

it('should create a ReactLink for state', function() {
pit('should create a ReactLink for state', async function() {
var Component = React.createClass({
mixins: [LinkedStateMixin],

Expand All @@ -35,7 +35,7 @@ describe('LinkedStateMixin', function() {
return <span>value is {this.state.value}</span>;
},
});
var component = ReactTestUtils.renderIntoDocument(<Component />);
var component = await ReactTestUtils.renderIntoDocumentAsync(<Component />);
var link = component.linkState('value');
expect(component.state.value).toBe('initial value');
expect(link.value).toBe('initial value');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('ReactContextValidator', function() {
// TODO: This behavior creates a runtime dependency on propTypes. We should
// ensure that this is not required for ES6 classes with Flow.

it('should filter out context not in contextTypes', function() {
pit('should filter out context not in contextTypes', async function() {
var Component = React.createClass({
contextTypes: {
foo: React.PropTypes.string,
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('ReactContextValidator', function() {
},
});

var instance = ReactTestUtils.renderIntoDocument(<ComponentInFooBarContext />);
var instance = await ReactTestUtils.renderIntoDocumentAsync(<ComponentInFooBarContext />);
reactComponentExpect(instance).expectRenderedChild().scalarContextEqual({foo: 'abc'});
});

Expand Down
10 changes: 5 additions & 5 deletions src/isomorphic/classic/class/__tests__/ReactBind-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var reactComponentExpect = require('reactComponentExpect');
// TODO: Test render and all stock methods.
describe('autobinding', function() {

it('Holds reference to instance', function() {
pit('Holds reference to instance', async function() {

var mouseDidEnter = jest.fn();
var mouseDidLeave = jest.fn();
Expand Down Expand Up @@ -51,13 +51,13 @@ describe('autobinding', function() {
});

var instance1 = <TestBindComponent />;
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
var mountedInstance1 = await ReactTestUtils.renderIntoDocumentAsync(instance1);
var rendered1 = reactComponentExpect(mountedInstance1)
.expectRenderedChild()
.instance();

var instance2 = <TestBindComponent />;
var mountedInstance2 = ReactTestUtils.renderIntoDocument(instance2);
var mountedInstance2 = await ReactTestUtils.renderIntoDocumentAsync(instance2);
var rendered2 = reactComponentExpect(mountedInstance2)
.expectRenderedChild()
.instance();
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('autobinding', function() {
expect(mouseDidLeave.mock.instances[1]).toBe(mountedInstance2);
});

it('works with mixins', function() {
pit('works with mixins', async function() {
var mouseDidClick = jest.fn();

var TestMixin = {
Expand All @@ -110,7 +110,7 @@ describe('autobinding', function() {
});

var instance1 = <TestBindComponent />;
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
var mountedInstance1 = await ReactTestUtils.renderIntoDocumentAsync(instance1);
var rendered1 = reactComponentExpect(mountedInstance1)
.expectRenderedChild()
.instance();
Expand Down
20 changes: 10 additions & 10 deletions src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var reactComponentExpect = require('reactComponentExpect');
// TODO: Test render and all stock methods.
describe('autobind optout', function() {

it('should work with manual binding', function() {
pit('should work with manual binding', async function() {

var mouseDidEnter = jest.fn();
var mouseDidLeave = jest.fn();
Expand All @@ -45,13 +45,13 @@ describe('autobind optout', function() {
});

var instance1 = <TestBindComponent />;
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
var mountedInstance1 = await ReactTestUtils.renderIntoDocumentAsync(instance1);
var rendered1 = reactComponentExpect(mountedInstance1)
.expectRenderedChild()
.instance();

var instance2 = <TestBindComponent />;
var mountedInstance2 = ReactTestUtils.renderIntoDocument(instance2);
var mountedInstance2 = await ReactTestUtils.renderIntoDocumentAsync(instance2);
var rendered2 = reactComponentExpect(mountedInstance2)
.expectRenderedChild()
.instance();
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('autobind optout', function() {
expect(mouseDidLeave.mock.instances[1]).toBe(mountedInstance2);
});

it('should not hold reference to instance', function() {
pit('should not hold reference to instance', async function() {
var mouseDidClick = function() {
void this.state.something;
};
Expand Down Expand Up @@ -110,13 +110,13 @@ describe('autobind optout', function() {
});

var instance1 = <TestBindComponent />;
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
var mountedInstance1 = await ReactTestUtils.renderIntoDocumentAsync(instance1);
var rendered1 = reactComponentExpect(mountedInstance1)
.expectRenderedChild()
.instance();

var instance2 = <TestBindComponent />;
var mountedInstance2 = ReactTestUtils.renderIntoDocument(instance2);
var mountedInstance2 = await ReactTestUtils.renderIntoDocumentAsync(instance2);
var rendered2 = reactComponentExpect(mountedInstance2)
.expectRenderedChild()
.instance();
Expand All @@ -137,7 +137,7 @@ describe('autobind optout', function() {
}).toThrow();
});

it('works with mixins that have not opted out of autobinding', function() {
pit('works with mixins that have not opted out of autobinding', async function() {
var mouseDidClick = jest.fn();

var TestMixin = {
Expand All @@ -153,7 +153,7 @@ describe('autobind optout', function() {
});

var instance1 = <TestBindComponent />;
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
var mountedInstance1 = await ReactTestUtils.renderIntoDocumentAsync(instance1);
var rendered1 = reactComponentExpect(mountedInstance1)
.expectRenderedChild()
.instance();
Expand All @@ -163,7 +163,7 @@ describe('autobind optout', function() {
expect(mouseDidClick.mock.instances[0]).toBe(mountedInstance1);
});

it('works with mixins that have opted out of autobinding', function() {
pit('works with mixins that have opted out of autobinding', async function() {
var mouseDidClick = jest.fn();

var TestMixin = {
Expand All @@ -180,7 +180,7 @@ describe('autobind optout', function() {
});

var instance1 = <TestBindComponent />;
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
var mountedInstance1 = await ReactTestUtils.renderIntoDocumentAsync(instance1);
var rendered1 = reactComponentExpect(mountedInstance1)
.expectRenderedChild()
.instance();
Expand Down
11 changes: 5 additions & 6 deletions src/isomorphic/classic/class/__tests__/ReactClass-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('ReactClass-spec', function() {
);
});

it('should support statics', function() {
pit('should support statics', async function() {
var Component = React.createClass({
statics: {
abc: 'def',
Expand All @@ -242,7 +242,7 @@ describe('ReactClass-spec', function() {
},
});
var instance = <Component />;
instance = ReactTestUtils.renderIntoDocument(instance);
instance = await ReactTestUtils.renderIntoDocumentAsync(instance);
expect(instance.constructor.abc).toBe('def');
expect(Component.abc).toBe('def');
expect(instance.constructor.def).toBe(0);
Expand All @@ -255,7 +255,7 @@ describe('ReactClass-spec', function() {
expect(Component.pqr()).toBe(Component);
});

it('should work with object getInitialState() return values', function() {
pit('should work with object getInitialState() return values', async function() {
var Component = React.createClass({
getInitialState: function() {
return {
Expand All @@ -267,7 +267,7 @@ describe('ReactClass-spec', function() {
},
});
var instance = <Component />;
instance = ReactTestUtils.renderIntoDocument(instance);
instance = await ReactTestUtils.renderIntoDocumentAsync(instance);
expect(instance.state.occupation).toEqual('clown');
});

Expand Down Expand Up @@ -311,9 +311,8 @@ describe('ReactClass-spec', function() {
return <span />;
},
});
var instance = <Component />;
expect(function() {
instance = ReactTestUtils.renderIntoDocument(instance);
ReactTestUtils.renderIntoDocument(<Component />);
}).toThrow(
'Component.getInitialState(): must return an object or null'
);
Expand Down
Loading

0 comments on commit f424a99

Please sign in to comment.