You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

5 years ago
export const tests = []
const t = (f) => tests.push(f)
const cantEdit = (fn) => {
try {
fn()
} catch (err) {
return true
}
}
t(() => nested.constructor === Object)
// nested is constant and can not be re-assigned
t(({ fail }) => nested && fail(() => (nested = 10)))
t(() => nested.obj.constructor === Object)
t(() => typeof nested.obj.str === 'string')
t(() => typeof nested.obj.num === 'number')
t(() => typeof nested.obj.bool === 'boolean')
t(() => Array.isArray(nested.arr))
t(() => nested.arr[0] === 4)
t(() => nested.arr[1] === undefined)
t(() => nested.arr[2] === '2')
t(() => nested.arr.length === 3)
// nested is frozen and can not be changed
t(() => cantEdit(() => (nested.obj = 5)))
t(() => nested.obj !== 5)
// nested.obj is also frozen and can not be changed
t(() => cantEdit(() => (nested.obj.update = 5)))
t(() => nested.obj.update === undefined)
// nested.arr is not frozen and can be changed
t(() => cantEdit(() => nested.arr.push('hot stuff')))
t(() => nested.arr.length === 3)
5 years ago
Object.freeze(tests)