Files
buuh/tests/browser/freeze.js
T

53 lines
1010 B
JavaScript
Raw Normal View History

const test = require('tape')
const choo = require('../../')
test('freeze (default)', function (t) {
t.plan(2)
const app = choo()
app.model({
state: {
foo: 'bar'
}
})
2017-01-07 02:18:13 +01:00
app.router(['/', function (state) {
// Modifying frozen objects can lead to TypeError
try {
state.foo = ''
} catch (e) {
}
2016-12-11 19:35:29 +01:00
t.equal(state.foo, 'bar', 'cannot modify property')
2017-01-07 02:18:13 +01:00
// Modifying frozen objects can lead to TypeError
try {
state.bar = 'baz'
} catch (e) {
}
2016-12-11 19:35:29 +01:00
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
}])
app.start()
})
test('noFreeze', function (t) {
t.plan(2)
2016-07-05 13:22:22 +02:00
const app = choo({freeze: false})
app.model({
state: {
foo: 'bar'
}
})
2017-01-07 02:18:13 +01:00
app.router(['/', function (state) {
2016-12-11 19:35:29 +01:00
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
}])
app.start()
})