From 303d92ff6acc029972ab3f1db58dfbe1f9b107b5 Mon Sep 17 00:00:00 2001 From: Haydn Ewers <27211+haydn@users.noreply.github.com> Date: Wed, 1 Sep 2021 22:31:58 +1000 Subject: [PATCH] Make tests to handle node and browser envs --- test.ts | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/test.ts b/test.ts index f6cc1fc..87af42e 100644 --- a/test.ts +++ b/test.ts @@ -17,6 +17,9 @@ import { createRecordSet, } from "./index.js"; +const nodeOnlyTest = typeof window === "object" ? test.skip : test; +const browserOnlyTest = typeof window === "object" ? test : test.skip; + const MINIMAL_SCHEMA: Schema = { Record: { meta: { @@ -1723,7 +1726,7 @@ describe("RecordSet persistence", () => { ]); }); - test("LocalStoragePersistence", () => { + browserOnlyTest("LocalStoragePersistence", () => { const getItemSpy = jest .spyOn(global.Storage.prototype, "getItem") .mockReturnValue( @@ -1766,7 +1769,7 @@ describe("RecordSet persistence", () => { setItemSpy.mockRestore(); }); - test("UrlPersistence", () => { + browserOnlyTest("UrlPersistence", () => { history.replaceState( null, "", @@ -2010,7 +2013,49 @@ describe("schema helpers", () => { }); describe("useRecordSet", () => { - test("end to end", () => { + nodeOnlyTest("local storage persistence doesn't error in node", () => { + expect(() => { + createRecordSet( + { + Person: { + meta: { + singular: "person", + plural: "people", + }, + fields: { + name: StringField(), + }, + }, + }, + { + persistence: "localStorage", + }, + ); + }).not.toThrow(); + }); + + nodeOnlyTest("url persistence works in node", () => { + expect(() => { + createRecordSet( + { + Person: { + meta: { + singular: "person", + plural: "people", + }, + fields: { + name: StringField(), + }, + }, + }, + { + persistence: "url", + }, + ); + }).not.toThrow(); + }); + + browserOnlyTest("end to end", () => { const { useRecordSet, updateRecordSet } = createRecordSet( { Role: { -- 2.51.2