Skip to content

failing test for property delete in schema #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions test/ChangeAPITest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ describe("Change API", () => {
sinon.assert.calledOnce(onChangeSpy);
sinon.assert.calledOnce(playerSpy);
});

it("should trigger onChange when removing child object", () => {
it("should trigger onChange when setting child object to null", () => {
const state = new State();
state.player = new Player("Jake", 10, 10);

Expand All @@ -130,6 +130,27 @@ describe("Change API", () => {

sinon.assert.calledOnce(onChangeSpy);
});

it("should trigger onChange when deleting child object", () => {
const state = new State();
state.player = new Player("Jake", 10, 10);

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

decodedState.onChange = function (changes: DataChange[]) {
console.log(changes);
assert.equal(changes.length, 1);
assert.equal(changes[0].field, "player");
assert.equal(changes[0].value, undefined);
}
let onChangeSpy = sinon.spy(decodedState, 'onChange');

delete state.player;
decodedState.decode(state.encode());

sinon.assert.calledOnce(onChangeSpy);
});
});

describe("ArraySchema", () => {
Expand Down