Skip to content

Commit

Permalink
additional test for snapshot swapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiamanzati committed Sep 15, 2017
1 parent 8d67e0b commit 8322ead
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,26 @@ test("it correctly reconciliate when swapping", t => {
t.deepEqual(s.todos.map(getPath), ["/todos/0", "/todos/1"])
})

test("it correctly reconciliate when swapping using snapshots", t => {
const Task = types.model("Task", {})
const Store = types.model({
todos: types.optional(types.array(Task), [])
})
const s = Store.create()
unprotect(s)
const a = Task.create()
const b = Task.create()
s.todos.push(a, b)
s.todos.replace([getSnapshot(b), getSnapshot(a)])
t.true(s.todos[0] === b)
t.true(s.todos[1] === a)
t.deepEqual(s.todos.map(getPath), ["/todos/0", "/todos/1"])
s.todos.push({})
t.true(s.todos[0] === b)
t.true(s.todos[1] === a)
t.deepEqual(s.todos.map(getPath), ["/todos/0", "/todos/1", "/todos/2"])
})

test("it should not be allowed to add the same item twice to the same store", t => {
const Task = types.model("Task", {})
const Store = types.model({
Expand Down

0 comments on commit 8322ead

Please sign in to comment.