Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion src/renderers/shared/fiber/__tests__/ReactCoroutine-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ describe('ReactCoroutine', () => {
ReactCoroutine = require('ReactCoroutine');
});

function div(...children) {
children = children.map(c => typeof c === 'string' ? { text: c } : c);
return { type: 'div', children, prop: undefined };
}

function span(prop) {
return { type: 'span', children: [], prop };
}

it('should render a coroutine', () => {
var ops = [];

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

// An alternative API could mark Continuation as something that needs
Expand Down Expand Up @@ -82,6 +91,64 @@ describe('ReactCoroutine', () => {
['Continuation', true],
['Continuation', false],
]);
expect(ReactNoop.getChildren()).toEqual([
div(
span('foo==bar'),
span('foo!=bar'),
),
]);
});

it('should update a coroutine', () => {
function Continuation({ isSame }) {
return <span prop={isSame ? 'foo==bar' : 'foo!=bar'} />;
}

function Child({ bar }) {
return ReactCoroutine.createYield({
bar: bar,
}, Continuation, null);
}

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

function HandleYields(props, yields) {
return yields.map(y =>
<y.continuation isSame={props.foo === y.props.bar} />
);
}

function Parent(props) {
return ReactCoroutine.createCoroutine(
props.children,
HandleYields,
props
);
}

function App(props) {
return <div><Parent foo={props.foo}><Indirection /></Parent></div>;
}

ReactNoop.render(<App foo={true} />);
ReactNoop.flush();
expect(ReactNoop.getChildren()).toEqual([
div(
span('foo==bar'),
span('foo!=bar'),
),
]);

ReactNoop.render(<App foo={false} />);
ReactNoop.flush();
expect(ReactNoop.getChildren()).toEqual([
div(
span('foo!=bar'),
span('foo==bar'),
),
]);
});

it('should unmount a composite in a coroutine', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This one is from #8406 as is

Expand Down