Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,12 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {

it('selector can throw on update', async () => {
const store = createExternalStore({a: 'a'});
const selector = state => state.a.toUpperCase();
const selector = state => {
if (typeof state.a !== 'string') {
throw new TypeError('Malformed state');
}
return state.a.toUpperCase();
};

function App() {
const a = useSyncExternalStoreWithSelector(
Expand All @@ -927,15 +932,18 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
await act(() => {
store.set({});
});
expect(container.textContent).toEqual(
"Cannot read property 'toUpperCase' of undefined",
);
expect(container.textContent).toEqual('Malformed state');
});

it('isEqual can throw on update', async () => {
const store = createExternalStore({a: 'A'});
const selector = state => state.a;
const isEqual = (left, right) => left.a.trim() === right.a.trim();
const isEqual = (left, right) => {
if (typeof left.a !== 'string' || typeof right.a !== 'string') {
throw new TypeError('Malformed state');
}
return left.a.trim() === right.a.trim();
};

function App() {
const a = useSyncExternalStoreWithSelector(
Expand Down Expand Up @@ -963,9 +971,7 @@ describe('Shared useSyncExternalStore behavior (shim and built-in)', () => {
await act(() => {
store.set({});
});
expect(container.textContent).toEqual(
"Cannot read property 'trim' of undefined",
);
expect(container.textContent).toEqual('Malformed state');
});
});
});