mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
[test] Add tests for cyclic arrays in Flight and Flight Reply (#35347)
We already had tests for cyclic objects, but not for cyclic arrays.
This commit is contained in:
@@ -724,6 +724,25 @@ describe('ReactFlight', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('can transport cyclic arrays', async () => {
|
||||
function ComponentClient({prop, obj}) {
|
||||
expect(prop[1]).toBe(prop);
|
||||
expect(prop[0]).toBe(obj);
|
||||
}
|
||||
const Component = clientReference(ComponentClient);
|
||||
|
||||
const obj = {};
|
||||
const cyclic = [obj];
|
||||
cyclic[1] = cyclic;
|
||||
const model = <Component prop={cyclic} obj={obj} />;
|
||||
|
||||
const transport = ReactNoopFlightServer.render(model);
|
||||
|
||||
await act(async () => {
|
||||
ReactNoop.render(await ReactNoopFlightClient.read(transport));
|
||||
});
|
||||
});
|
||||
|
||||
it('can render a lazy component as a shared component on the server', async () => {
|
||||
function SharedComponent({text}) {
|
||||
return (
|
||||
|
||||
@@ -650,6 +650,17 @@ describe('ReactFlightDOMReply', () => {
|
||||
expect(root.prop.obj).toBe(root.prop);
|
||||
});
|
||||
|
||||
it('can transport cyclic arrays', async () => {
|
||||
const obj = {};
|
||||
const cyclic = [obj];
|
||||
cyclic[1] = cyclic;
|
||||
|
||||
const body = await ReactServerDOMClient.encodeReply({prop: cyclic, obj});
|
||||
const root = await ReactServerDOMServer.decodeReply(body, webpackServerMap);
|
||||
expect(root.prop[1]).toBe(root.prop);
|
||||
expect(root.prop[0]).toBe(root.obj);
|
||||
});
|
||||
|
||||
it('can abort an unresolved model and get the partial result', async () => {
|
||||
const promise = new Promise(r => {});
|
||||
const controller = new AbortController();
|
||||
|
||||
Reference in New Issue
Block a user