-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase test coverage around node handlers
- Loading branch information
Showing
4 changed files
with
226 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { describe, expect, it } from "vitest" | ||
|
||
import { Arbor } from "../../src/arbor" | ||
|
||
describe("ArrayHandler", () => { | ||
describe("Symbol.iterator", () => { | ||
it("exposes child nodes via iterator", () => { | ||
const store = new Arbor([ | ||
{ name: "Alice" }, | ||
{ name: "Bob" }, | ||
{ name: "Carol" }, | ||
]) | ||
|
||
const alice = store.state[0] | ||
const bob = store.state[1] | ||
const carol = store.state[2] | ||
|
||
const iterator = store.state[Symbol.iterator]() | ||
|
||
const user1 = iterator.next().value | ||
const user2 = iterator.next().value | ||
const user3 = iterator.next().value | ||
|
||
expect(user1).toBe(alice) | ||
expect(user2).toBe(bob) | ||
expect(user3).toBe(carol) | ||
}) | ||
|
||
it("exposes child nodes", () => { | ||
const store = new Arbor([ | ||
{ name: "Alice" }, | ||
{ name: "Bob" }, | ||
{ name: "Carol" }, | ||
]) | ||
|
||
const alice = store.state[0] | ||
const bob = store.state[1] | ||
const carol = store.state[2] | ||
|
||
const entries = Object.entries(store.state) | ||
|
||
expect(entries[0][0]).toEqual("0") | ||
expect(entries[0][1]).toBe(alice) | ||
expect(entries[1][0]).toEqual("1") | ||
expect(entries[1][1]).toBe(bob) | ||
expect(entries[2][0]).toEqual("2") | ||
expect(entries[2][1]).toBe(carol) | ||
}) | ||
|
||
it("exposes child nodes via spread operator", () => { | ||
const store = new Arbor([ | ||
{ name: "Alice" }, | ||
{ name: "Bob" }, | ||
{ name: "Carol" }, | ||
]) | ||
|
||
const alice = store.state[0] | ||
const bob = store.state[1] | ||
const carol = store.state[2] | ||
|
||
const users = [...store.state] | ||
|
||
expect(users[0]).toBe(alice) | ||
expect(users[1]).toBe(bob) | ||
expect(users[2]).toBe(carol) | ||
}) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { describe, expect, it } from "vitest" | ||
|
||
import { Arbor } from "../../src/arbor" | ||
|
||
describe("DefaultHandler", () => { | ||
describe("Symbol.iterator", () => { | ||
it("exposes child nodes via Object.entries", () => { | ||
const store = new Arbor({ | ||
user1: { name: "Alice" }, | ||
user2: { name: "Bob" }, | ||
user3: { name: "Carol" }, | ||
}) | ||
|
||
const alice = store.state.user1 | ||
const bob = store.state.user2 | ||
const carol = store.state.user3 | ||
|
||
const entries = Object.entries(store.state) | ||
|
||
expect(entries[0][0]).toEqual("user1") | ||
expect(entries[0][1]).toBe(alice) | ||
expect(entries[1][0]).toEqual("user2") | ||
expect(entries[1][1]).toBe(bob) | ||
expect(entries[2][0]).toEqual("user3") | ||
expect(entries[2][1]).toBe(carol) | ||
}) | ||
|
||
it("exposes child nodes via spread operator", () => { | ||
const store = new Arbor({ | ||
user1: { name: "Alice" }, | ||
user2: { name: "Bob" }, | ||
user3: { name: "Carol" }, | ||
}) | ||
|
||
const alice = store.state.user1 | ||
const bob = store.state.user2 | ||
const carol = store.state.user3 | ||
|
||
const users = { ...store.state } | ||
|
||
expect(users.user1).toBe(alice) | ||
expect(users.user2).toBe(bob) | ||
expect(users.user3).toBe(carol) | ||
}) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { describe, expect, it } from "vitest" | ||
|
||
import { Arbor } from "../../src/arbor" | ||
|
||
describe("MapHandler", () => { | ||
describe("Symbol.iterator", () => { | ||
it("exposes child nodes via Map#entries", () => { | ||
const store = new Arbor( | ||
new Map([ | ||
[0, { name: "Alice" }], | ||
[1, { name: "Bob" }], | ||
[2, { name: "Carol" }], | ||
]) | ||
) | ||
|
||
const alice = store.state.get(0) | ||
const bob = store.state.get(1) | ||
const carol = store.state.get(2) | ||
|
||
const entries = store.state.entries() | ||
|
||
const entry1 = entries.next().value | ||
const entry2 = entries.next().value | ||
const entry3 = entries.next().value | ||
|
||
expect(entry1[0]).toEqual(0) | ||
expect(entry1[1]).toBe(alice) | ||
expect(entry2[0]).toEqual(1) | ||
expect(entry2[1]).toBe(bob) | ||
expect(entry3[0]).toEqual(2) | ||
expect(entry3[1]).toBe(carol) | ||
}) | ||
|
||
it("exposes child nodes via iterator", () => { | ||
const store = new Arbor( | ||
new Map([ | ||
[0, { name: "Alice" }], | ||
[1, { name: "Bob" }], | ||
[2, { name: "Carol" }], | ||
]) | ||
) | ||
|
||
const alice = store.state.get(0) | ||
const bob = store.state.get(1) | ||
const carol = store.state.get(2) | ||
|
||
const entries = store.state[Symbol.iterator]() | ||
|
||
const entry1 = entries.next().value | ||
const entry2 = entries.next().value | ||
const entry3 = entries.next().value | ||
|
||
expect(entry1[0]).toEqual(0) | ||
expect(entry1[1]).toBe(alice) | ||
expect(entry2[0]).toEqual(1) | ||
expect(entry2[1]).toBe(bob) | ||
expect(entry3[0]).toEqual(2) | ||
expect(entry3[1]).toBe(carol) | ||
}) | ||
|
||
it("exposes child nodes via spread operator", () => { | ||
const store = new Arbor( | ||
new Map([ | ||
[0, { name: "Alice" }], | ||
[1, { name: "Bob" }], | ||
[2, { name: "Carol" }], | ||
]) | ||
) | ||
|
||
const alice = store.state.get(0) | ||
const bob = store.state.get(1) | ||
const carol = store.state.get(2) | ||
|
||
const entries = [...store.state] | ||
|
||
const entry1 = entries[0] | ||
const entry2 = entries[1] | ||
const entry3 = entries[2] | ||
|
||
expect(entry1[0]).toEqual(0) | ||
expect(entry1[1]).toBe(alice) | ||
expect(entry2[0]).toEqual(1) | ||
expect(entry2[1]).toBe(bob) | ||
expect(entry3[0]).toEqual(2) | ||
expect(entry3[1]).toBe(carol) | ||
}) | ||
}) | ||
}) |
This file contains 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