From cf8b1a9d0796177071c9ec8dc2750686befa4506 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sun, 23 Jul 2023 10:10:03 -0300 Subject: [PATCH] ArraySchema: add failing test case for .setAt() with undefined value --- test/ArraySchemaTest.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/ArraySchemaTest.ts b/test/ArraySchemaTest.ts index 8414f353..0ba038d2 100644 --- a/test/ArraySchemaTest.ts +++ b/test/ArraySchemaTest.ts @@ -5,6 +5,23 @@ import { State, Player } from "./Schema"; import { ArraySchema, Schema, type, Reflection, filter, MapSchema, dumpChanges, filterChildren } from "../src"; describe("ArraySchema Tests", () => { + xit("should allow to setAt an undefined value", () => { + class Block extends Schema { + @type("number") num: number; + } + class State extends Schema { + @type([Block]) blocks = new ArraySchema(); + } + const state = new State(); + state.blocks.push(new Block().assign({ num: 1 })); + state.blocks.push(undefined); + + const decodedState = new State(); + decodedState.decode(state.encode()); + assert.strictEqual(decodedState.blocks.length, 2); + assert.ok(decodedState.blocks.at(0) instanceof Block); + assert.ok(decodedState.blocks.at(1) === undefined); + }); it("should trigger onAdd / onRemove properly on splice", () => { class Item extends Schema {