diff options
author | Florian Dold <florian@dold.me> | 2021-02-24 17:33:07 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-02-24 17:33:07 +0100 |
commit | 564e4f8710388ab2ae40c959c497f2e0260199ed (patch) | |
tree | 1d9f1b835bf6580977158f5eee133f8fa39f67d4 /packages/idb-bridge/src/util/structuredClone.test.ts | |
parent | bc7956c2ba685e459c94204ca30f85eef881d0ac (diff) | |
download | wallet-core-564e4f8710388ab2ae40c959c497f2e0260199ed.tar.gz wallet-core-564e4f8710388ab2ae40c959c497f2e0260199ed.tar.bz2 wallet-core-564e4f8710388ab2ae40c959c497f2e0260199ed.zip |
idb: encapsulate non-JSON data correctly
Diffstat (limited to 'packages/idb-bridge/src/util/structuredClone.test.ts')
-rw-r--r-- | packages/idb-bridge/src/util/structuredClone.test.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/packages/idb-bridge/src/util/structuredClone.test.ts b/packages/idb-bridge/src/util/structuredClone.test.ts new file mode 100644 index 000000000..58a7f32c1 --- /dev/null +++ b/packages/idb-bridge/src/util/structuredClone.test.ts @@ -0,0 +1,39 @@ +/* + Copyright 2019 Florian Dold + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the License for the specific language governing + permissions and limitations under the License. +*/ + +import test, { ExecutionContext } from "ava"; +import { structuredClone } from "./structuredClone"; + +function checkClone(t: ExecutionContext, x: any): void { + t.deepEqual(structuredClone(x), x); +} + +test("structured clone", (t) => { + checkClone(t, "foo"); + checkClone(t, [1, 2]); + checkClone(t, { x1: "foo" }); + checkClone(t, new Date()); + checkClone(t, [new Date()]); + checkClone(t, undefined); + checkClone(t, [undefined]); +}); + +test("structured clone (cycles)", (t) => { + const obj1: any[] = [1, 2]; + obj1.push(obj1); + const obj1Clone = structuredClone(obj1); + t.is(obj1Clone, obj1Clone[2]); +}); |