Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce09e26
commit 111d286
Showing
1 changed file
with
36 additions
and
0 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,36 @@ | ||
import { getSnapshot, applySnapshot, unprotect, types } from "../src" | ||
import { test } from "ava" | ||
|
||
test("it should avoid processing patch if is exactly the current one in applySnapshot", t => { | ||
let called = false | ||
const Model = types.model({ | ||
a: types.number, | ||
b: types.string | ||
}) | ||
|
||
const store = Model.create({ a: 1, b: "hello" }) | ||
called = false | ||
|
||
const snapshot = getSnapshot(store) | ||
applySnapshot(store, snapshot) | ||
t.is(getSnapshot(store), snapshot) // no new snapshot emitted | ||
}) | ||
|
||
test("it should avoid processing patch if is exactly the current one in reconcile", t => { | ||
const Model = types.model({ | ||
a: types.number, | ||
b: types.string | ||
}) | ||
|
||
const RootModel = types.model({ | ||
a: Model | ||
}) | ||
|
||
const store = RootModel.create({ a: { a: 1, b: "hello" } }) | ||
unprotect(store) | ||
|
||
const snapshot = getSnapshot(store) | ||
store.a = snapshot.a | ||
t.is(getSnapshot(store.a), snapshot.a) | ||
t.deepEqual(getSnapshot(store), snapshot) | ||
}) |