##// END OF EJS Templates
Added tag v1.9.0-rc3 for changeset 98b2c550c676
Added tag v1.9.0-rc3 for changeset 98b2c550c676

File last commit:

r136:435ce00ba245 v1.9.0-rc2 default
r139:9c8af9e9ba6f default
Show More
observable-store-tests.ts
64 lines | 1.7 KiB | video/mp2t | TypeScriptLexer
/ djx / src / test / ts / observable-store-tests.ts
import Memory = require("dojo/store/Memory");
import Observerable = require("dojo/store/Observable");
import { get } from "./store";
import tap = require("tap");
interface Person {
id: string;
name: string;
age: number;
}
tap.test("store::get(...) tests", async t => {
const store = new Observerable(new Memory<Person>());
const getPerson = get(store);
const peterId = "id:peter";
const samId = "id:sam";
const peter = getPerson(peterId);
const sam = getPerson(samId);
const seq1 = await getPerson(peterId, { observe: false }).collect();
t.ok(seq1.length === 0, "Should be empty sequence");
let peterChangeCount = 0;
let samChangeCount = 0;
let peterDeleted = 0;
const peterSubscription = peter.subscribe({
next: () => peterChangeCount++,
complete: () => peterDeleted++
});
const samSubscription = sam.subscribe({
next: () => samChangeCount++
});
try {
t.equal(peterChangeCount, 0, "Should be no changes recorded");
store.put({id: peterId, name: "Peter", age: 30 });
t.equal(peterChangeCount, 1, "Should record 1 object change");
t.equal(samChangeCount, 0, "Should not record other object changes");
store.remove(peterId);
t.equal(peterDeleted, 1, "Should complete sequence");
t.equal(peterChangeCount, 1, "Should not record remove operations");
store.put({id: peterId, name: "Peter", age: 29});
t.equal(peterChangeCount, 1, "Should not record changes after completion");
} finally {
peterSubscription.unsubscribe();
samSubscription.unsubscribe();
}
}).catch(() => { });