Skip to content

Commit 10e5920

Browse files
Implement test for custom serializers in getScope
1 parent af85259 commit 10e5920

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/get-scope.browser.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ describe("getClientScope", () => {
159159

160160
expect(clientScopeTwo.getState($count)).toEqual(4);
161161
});
162+
163+
test("should support custom serializers", async () => {
164+
const $homeDate = createStore<Date | null>(null, {
165+
serialize: {
166+
read: (dateStringOrNull) =>
167+
typeof dateStringOrNull === "string" ? new Date(dateStringOrNull) : null,
168+
write: (dateOrNull) => (dateOrNull ? dateOrNull.toISOString() : null),
169+
},
170+
});
171+
172+
const serverScope = fork();
173+
174+
await allSettled($homeDate, {scope: serverScope, params: new Date(2024, 10, 3) });
175+
176+
const values = serialize(serverScope);
177+
178+
const scope = getScope(values);
179+
180+
const clientValue = scope.getState($homeDate);
181+
182+
console.log(clientValue);
183+
184+
expect(clientValue instanceof Date).toBe(true);
185+
});
162186
});
163187

164188
describe("getScope implementation details", () => {

0 commit comments

Comments
 (0)