Skip to content

Commit

Permalink
ArraySchema: add failing test case for .setAt() with undefined value
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Jul 23, 2023
1 parent 9abe3e4 commit cf8b1a9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/ArraySchemaTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Block>();
}
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 {
Expand Down

0 comments on commit cf8b1a9

Please sign in to comment.