2016-07-03 16:35:58 -07:00
|
|
|
const test = require('tape')
|
|
|
|
|
const choo = require('../../')
|
|
|
|
|
|
|
|
|
|
test('freeze (default)', function (t) {
|
|
|
|
|
t.plan(2)
|
|
|
|
|
const app = choo()
|
|
|
|
|
|
|
|
|
|
app.model({
|
|
|
|
|
state: {
|
|
|
|
|
foo: 'bar'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2016-12-11 19:35:29 +01:00
|
|
|
app.router(['/', function (state, prev, send) {
|
|
|
|
|
state.foo = ''
|
|
|
|
|
t.equal(state.foo, 'bar', 'cannot modify property')
|
|
|
|
|
state.bar = 'baz'
|
|
|
|
|
t.equal(state.bar, undefined, 'cannot add property')
|
2016-12-22 06:55:36 -05:00
|
|
|
return document.createElement('div')
|
2016-12-11 19:35:29 +01:00
|
|
|
}])
|
2016-07-03 16:35:58 -07:00
|
|
|
|
|
|
|
|
app.start()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('noFreeze', function (t) {
|
|
|
|
|
t.plan(2)
|
2016-07-05 13:22:22 +02:00
|
|
|
const app = choo({freeze: false})
|
2016-07-03 16:35:58 -07:00
|
|
|
|
|
|
|
|
app.model({
|
|
|
|
|
state: {
|
|
|
|
|
foo: 'bar'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2016-12-11 19:35:29 +01:00
|
|
|
app.router(['/', function (state, prev, send) {
|
|
|
|
|
state.foo = ''
|
|
|
|
|
t.equal(state.foo, '', 'can modify property')
|
|
|
|
|
state.bar = 'baz'
|
|
|
|
|
t.equal(state.bar, 'baz', 'can add property')
|
2016-12-22 06:55:36 -05:00
|
|
|
return document.createElement('div')
|
2016-12-11 19:35:29 +01:00
|
|
|
}])
|
2016-07-03 16:35:58 -07:00
|
|
|
|
|
|
|
|
app.start()
|
|
|
|
|
})
|