cover all

This commit is contained in:
harttle
2017-08-14 22:07:08 +08:00
parent 7904f823a8
commit 72597c52e5
14 changed files with 268 additions and 205 deletions
+20 -3
View File
@@ -98,7 +98,13 @@ describe('scope', function () {
expect(scope.get('bar[foo]')).to.equal('coo')
})
it('should support nested case', function () {
it('should return undefined when not exist', function () {
expect(scope.get('foo.foo.foo')).to.be.undefined
})
})
describe('#set', function () {
it('should set nested value', function () {
scope.set('posts', {
'first': {
'name': 'A Nice Day'
@@ -109,8 +115,12 @@ describe('scope', function () {
})
expect(scope.get('posts[category.diary[0]].name'), 'A Nice Day')
})
})
it('should create parents if needed', function () {
scope.set('foo.bar.coo', 'COO')
expect(scope.get('foo.bar.coo'), 'COO')
})
})
describe('strict_variables', function () {
var scope
beforeEach(function () {
@@ -118,12 +128,19 @@ describe('scope', function () {
strict_variables: true
})
})
it('should throw undefined in strict mode', function () {
it('should throw when variable not defined', function () {
function fn () {
scope.get('notdefined')
}
expect(fn).to.throw(/undefined variable: notdefined/)
})
it('should throw when deep variable not exist', function () {
scope.set('foo', 'bar')
function fn () {
scope.get('foo.bar.not.defined')
}
expect(fn).to.throw(/undefined variable: not/)
})
it('should find variable in parent scope', function () {
scope.set('foo', 'foo')
scope.push({