schema icon indicating copy to clipboard operation
schema copied to clipboard

[Bug]: ArraySchema: consecutive .unshift() calls are not encoded properly

Open endel opened this issue 8 months ago • 0 comments

The following test case is not passing:

class State extends Schema {
    @type(["number"]) arrayOfNumbers = new ArraySchema<number>();
}

const state = new State();
state.arrayOfNumbers.push(1);
state.arrayOfNumbers.push(2);
state.arrayOfNumbers.push(3);

const decodedState = new State();
decodedState.decode(state.encode());

// HERE: consecutive unshift calls aren't encoded properly.
state.arrayOfNumbers.unshift(0);
state.arrayOfNumbers.unshift(-1);
assert.strictEqual(-1, state.arrayOfNumbers[0]);

decodedState.decode(state.encode());
assert.deepStrictEqual([-1, 0, 1, 2, 3], decodedState.arrayOfNumbers.toJSON()); // FAILS

endel avatar Mar 28 '25 17:03 endel