Created
April 1, 2018 21:22
-
-
Save endel/ae4dee520babea72106313412af1eb3d to your computer and use it in GitHub Desktop.
Test case for https://github.com/gamestdio/state-listener/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///<reference types="mocha" /> | |
import { assert, expect } from "chai"; | |
import { StateContainer, DataChange } from "../src"; | |
function clone (data: any) { | |
return JSON.parse(JSON.stringify(data)); | |
} | |
describe("StateContainer", () => { | |
let container: StateContainer<any>; | |
let data: any; | |
beforeEach(() => { | |
data = { | |
npc_entities: { | |
npc: { | |
one: { x: 10, y: 0 }, | |
two: { x: 0, y: 0 }, | |
} | |
} | |
}; | |
container = new StateContainer<any>(clone(data)); | |
}); | |
it("should trigger container callbacks before its properties", () => { | |
let container = new StateContainer({}); | |
let npcs: any = {}; | |
container.listen("npc_entities/npc/:id", (change: DataChange) => { | |
npcs[change.path.id] = change.value; | |
}); | |
container.listen("npc_entities/npc/:id/:attribute", (change: DataChange) => { | |
const npcId = change.path.id; | |
const attribute = change.path.attribute; | |
assert.ok(npcs[npcId], "npc should already exist"); | |
assert.equal(npcs[npcId][attribute], change.value); | |
}); | |
container.set(clone(data)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment