Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fiber] Simple test assertions #6931

Merged
merged 1 commit into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought these were commented out. :)


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);
});

});