Skip to content

Commit d1a3257

Browse files
committed
test: Add test case for non-lazy suspending child
1 parent 525544a commit d1a3257

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/router.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,45 @@ describe('Router', () => {
888888
pushState.restore();
889889
replaceState.restore();
890890
});
891+
892+
it('should support using `Router` as an implicit suspense boundary', async () => {
893+
let data;
894+
function useSuspense() {
895+
const [_, update] = useState();
896+
897+
if (!data) {
898+
data = new Promise(r => setTimeout(r, 5, 'data'));
899+
data.then(
900+
(res) => update((data.res = res)),
901+
(err) => update((data.err = err))
902+
);
903+
}
904+
905+
if (data.res) return data.res;
906+
if (data.err) throw data.err;
907+
throw data;
908+
}
909+
910+
render(
911+
<LocationProvider>
912+
<Router>
913+
<Route
914+
path="/"
915+
component={() => {
916+
const result = useSuspense();
917+
return <h1>{result}</h1>;
918+
}}
919+
/>
920+
</Router>
921+
<ShallowLocation />
922+
</LocationProvider>,
923+
scratch
924+
);
925+
926+
expect(scratch).to.have.property('textContent', '');
927+
await sleep(10);
928+
expect(scratch).to.have.property('textContent', 'data');
929+
});
891930
});
892931

893932
const MODE_HYDRATE = 1 << 5;

0 commit comments

Comments
 (0)