зеркало из https://github.com/mozilla/reflex.git
Update tests.
This commit is contained in:
Родитель
68e45cf789
Коммит
92b90603a4
|
@ -0,0 +1,43 @@
|
|||
/* vim:set ts=2 sw=2 sts=2 expandtab */
|
||||
/*jshint asi: true undef: true es5: true node: true browser: true devel: true
|
||||
forin: true latedef: false globalstrict: true*/
|
||||
|
||||
"use strict";
|
||||
|
||||
var state = require("../state")
|
||||
var patch = require("../state/patch")
|
||||
var diff = require("../state/diff")
|
||||
|
||||
// Utility that resets prototype of hash back to Object.prototype
|
||||
function reset(hash) { return JSON.parse(JSON.stringify(hash)) }
|
||||
|
||||
|
||||
exports["test one"] = function (assert) {
|
||||
var s1 = state()
|
||||
|
||||
assert.equal(diff(s1), s1, "diff for for initial state is itself")
|
||||
assert.deepEqual(reset(s1), {}, "initial state is empty hash")
|
||||
|
||||
var delta1 = {
|
||||
foo: { bar: "baz" },
|
||||
foo2: { l: "x" }
|
||||
}
|
||||
var s2 = patch(s1, delta1)
|
||||
|
||||
assert.equal(diff(s2), delta1, "diff returns delta applied to previous state")
|
||||
assert.deepEqual(reset(s2), {
|
||||
foo: { bar: "baz" },
|
||||
foo2: { l: "x" }
|
||||
}, "first patch was applied properly")
|
||||
|
||||
var delta2 = { x: "42", foo: { baz: "bar" } }
|
||||
|
||||
var s3 = patch(s2, delta2)
|
||||
|
||||
assert.equal(diff(s3), delta2, "diff returns delta applied to previous state")
|
||||
assert.deepEqual(reset(s3), {
|
||||
foo: { bar: "baz", baz: "bar" },
|
||||
foo2: { l: "x" },
|
||||
x: "42"
|
||||
}, "nested changes applied properly")
|
||||
}
|
|
@ -4,65 +4,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var State = require("../state")
|
||||
var patch = State.patch
|
||||
var diff = State.diff
|
||||
|
||||
exports["test one"] = function (assert) {
|
||||
var s = new State()
|
||||
var delta = diff(s)
|
||||
|
||||
assert.deepEqual(s, {}, "initial state")
|
||||
assert.equal(JSON.stringify(s), "{}", "patch value 1")
|
||||
assert.strictEqual(delta, null, "delta value 1")
|
||||
|
||||
var s2 = patch(s, {
|
||||
foo: {
|
||||
bar: "baz"
|
||||
}
|
||||
, foo2: {
|
||||
l: "x"
|
||||
}
|
||||
})
|
||||
var delta2 = diff(s2)
|
||||
assert.equal(JSON.stringify(delta2), JSON.stringify({
|
||||
foo: {
|
||||
bar: "baz"
|
||||
}
|
||||
, foo2: {
|
||||
l: "x"
|
||||
}
|
||||
}), "delta value 2")
|
||||
|
||||
assert.equal(JSON.stringify(s2), JSON.stringify({
|
||||
foo: {
|
||||
bar: "baz"
|
||||
}
|
||||
, foo2: {
|
||||
l: "x"
|
||||
}
|
||||
}), "patch value 2")
|
||||
|
||||
var s3 = patch(s2, {
|
||||
x: "42"
|
||||
, foo: "53"
|
||||
})
|
||||
var delta3 = diff(s3)
|
||||
|
||||
assert.equal(JSON.stringify(delta3), JSON.stringify({
|
||||
x: "42"
|
||||
, foo: "53"
|
||||
}), "delta value 3")
|
||||
|
||||
assert.equal(JSON.stringify(s3), JSON.stringify({
|
||||
|
||||
foo: "53"
|
||||
, foo2: {
|
||||
l: "x"
|
||||
}
|
||||
, x: "42"
|
||||
}), "patch value 3")
|
||||
}
|
||||
exports["test state"] = require("./state")
|
||||
|
||||
if (module === require.main) {
|
||||
require("test").run(exports)
|
||||
|
|
Загрузка…
Ссылка в новой задаче