mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #6931 from sebmarkbage/newreconciler
[Fiber] Simple test assertions
(cherry picked from commit dc5686a42f)
This commit is contained in:
committed by
Paul O’Shannessy
parent
ab4ea744f9
commit
39ddfdd9a2
+22
-37
@@ -15,7 +15,7 @@ var React;
|
||||
var ReactNoop;
|
||||
var ReactCoroutine;
|
||||
|
||||
describe('ReactComponent', function() {
|
||||
describe('ReactCoroutine', function() {
|
||||
beforeEach(function() {
|
||||
React = require('React');
|
||||
ReactNoop = require('ReactNoop');
|
||||
@@ -23,61 +23,32 @@ describe('ReactComponent', function() {
|
||||
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} />,
|
||||
];
|
||||
}
|
||||
|
||||
ReactNoop.render(<Foo />);
|
||||
// console.log('Nothing done');
|
||||
ReactNoop.flushLowPri(7);
|
||||
// console.log('Yield');
|
||||
ReactNoop.flushLowPri(50);
|
||||
// console.log('Done');
|
||||
});
|
||||
|
||||
it('should render a coroutine', function() {
|
||||
|
||||
var ops = [];
|
||||
|
||||
|
||||
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} />
|
||||
);
|
||||
@@ -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,
|
||||
@@ -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],
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user