forked from MithrilJS/mithril.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmithril.prop.js
64 lines (50 loc) · 1.41 KB
/
mithril.prop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
describe("m.prop()", function () {
"use strict"
it("reads correct value", function () {
var prop = m.prop("test")
expect(prop()).to.equal("test")
})
it("defaults to `undefined`", function () {
var prop = m.prop()
expect(prop()).to.be.undefined
})
it("sets the correct value", function () {
var prop = m.prop("test")
prop("foo")
expect(prop()).to.equal("foo")
})
it("sets `null`", function () {
var prop = m.prop(null)
expect(prop()).to.be.null
})
it("sets `undefined`", function () {
var prop = m.prop(undefined)
expect(prop()).to.be.undefined
})
it("returns the new value when set", function () {
var prop = m.prop()
expect(prop("foo")).to.equal("foo")
})
it("correctly stringifies to the correct value", function () {
var prop = m.prop("test")
expect(JSON.stringify(prop)).to.equal('"test"')
})
it("correctly stringifies to the correct value as a child", function () {
var obj = {prop: m.prop("test")}
expect(JSON.stringify(obj)).to.equal('{"prop":"test"}')
})
it("correctly wraps Mithril promises", function () {
var defer = m.deferred()
var prop = m.prop(defer.promise)
defer.resolve("test")
expect(prop()).to.equal("test")
})
it("returns a thenable when wrapping a Mithril promise", function () {
var defer = m.deferred()
var prop = m.prop(defer.promise).then(function () {
return "test2"
})
defer.resolve("test")
expect(prop()).to.equal("test2")
})
})