Skip to content

Commit

Permalink
Merge pull request #6931 from sebmarkbage/newreconciler
Browse files Browse the repository at this point in the history
[Fiber] Simple test assertions
(cherry picked from commit dc5686a)
  • Loading branch information
sebmarkbage authored and zpao committed Jun 14, 2016
1 parent ab4ea74 commit 39ddfdd
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,69 +15,40 @@ var React;
var ReactNoop;
var ReactCoroutine;

describe('ReactComponent', function() {
describe('ReactCoroutine', function() {
beforeEach(function() {
React = require('React');
ReactNoop = require('ReactNoop');
ReactCoroutine = require('ReactCoroutine');
spyOn(console, 'log');
});

it('should render a simple component', function() {

function Bar() {
return <div>Hello World</div>;
}

function Foo() {
return <Bar isBar={true} />;
}

ReactNoop.render(<Foo />);
ReactNoop.flush();

});

it('should render a simple component, in steps if needed', function() {

function Bar() {
return <span><div>Hello World</div></span>;
}

function Foo() {
return [
<Bar isBar={true} />,
<Bar isBar={true} />,
];
}
it('should render a coroutine', function() {

ReactNoop.render(<Foo />);
// console.log('Nothing done');
ReactNoop.flushLowPri(7);
// console.log('Yield');
ReactNoop.flushLowPri(50);
// console.log('Done');
});
var ops = [];

it('should render a coroutine', function() {

function Continuation({ isSame }) {
ops.push(['Continuation', isSame]);
return <span>{isSame ? 'foo==bar' : 'foo!=bar'}</span>;
}

// An alternative API could mark Continuation as something that needs
// yielding. E.g. Continuation.yieldType = 123;
function Child({ bar }) {
ops.push(['Child', bar]);
return ReactCoroutine.createYield({
bar: bar,
}, Continuation, null);
}

function Indirection() {
ops.push('Indirection');
return [<Child bar={true} />, <Child bar={false} />];
}

function HandleYields(props, yields) {
ops.push('HandleYields');
return yields.map(y =>
<y.continuation isSame={props.foo === y.props.bar} />
);
Expand All @@ -86,6 +57,7 @@ describe('ReactComponent', function() {
// An alternative API could mark Parent as something that needs
// yielding. E.g. Parent.handler = HandleYields;
function Parent(props) {
ops.push('Parent');
return ReactCoroutine.createCoroutine(
props.children,
HandleYields,
Expand All @@ -100,6 +72,19 @@ describe('ReactComponent', function() {
ReactNoop.render(<App />);
ReactNoop.flush();

expect(ops).toEqual([
'Parent',
'Indirection',
['Child', true],
// Yield
['Child', false],
// Yield
'HandleYields',
// Continue yields
['Continuation', true],
['Continuation', false],
]);

});

});
69 changes: 69 additions & 0 deletions src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails react-core
*/

'use strict';

var React;
var ReactNoop;

describe('ReactIncremental', function() {
beforeEach(function() {
React = require('React');
ReactNoop = require('ReactNoop');
spyOn(console, 'log');
});

it('should render a simple component', function() {

function Bar() {
return <div>Hello World</div>;
}

function Foo() {
return <Bar isBar={true} />;
}

ReactNoop.render(<Foo />);
ReactNoop.flush();

});

it('should render a simple component, in steps if needed', function() {

var barCalled = false;
function Bar() {
barCalled = true;
return <span><div>Hello World</div></span>;
}

var fooCalled = false;
function Foo() {
fooCalled = true;
return [
<Bar isBar={true} />,
<Bar isBar={true} />,
];
}

ReactNoop.render(<Foo />);
expect(fooCalled).toBe(false);
expect(barCalled).toBe(false);
// Do one step of work.
ReactNoop.flushLowPri(7);
expect(fooCalled).toBe(true);
expect(barCalled).toBe(false);
// Do the rest of the work.
ReactNoop.flushLowPri(50);
expect(fooCalled).toBe(true);
expect(barCalled).toBe(true);
});

});

0 comments on commit 39ddfdd

Please sign in to comment.