|
|
@@ -664,29 +664,23 @@ describe('UNIT: API', function () {
|
|
|
|
|
|
describe('hooks', function () {
|
|
|
|
|
|
- describe('beforeCompile / created', function () {
|
|
|
+ describe('created', function () {
|
|
|
|
|
|
it('should be called before compile', function () {
|
|
|
|
|
|
var called = false,
|
|
|
- Test = Vue.extend({ beforeCompile: function (options) {
|
|
|
- assert.ok(options.ok)
|
|
|
- called = true
|
|
|
- }}),
|
|
|
- Test2 = Vue.extend({ created: function (options) {
|
|
|
+ Test = Vue.extend({ created: function (options) {
|
|
|
assert.ok(options.ok)
|
|
|
called = true
|
|
|
}})
|
|
|
new Test({ ok: true })
|
|
|
assert.ok(called)
|
|
|
- called = false
|
|
|
- new Test2({ ok: true })
|
|
|
- assert.ok(called)
|
|
|
+
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
- describe('afterCompile / ready', function () {
|
|
|
+ describe('ready', function () {
|
|
|
|
|
|
it('should be called after compile with options', function () {
|
|
|
var called = false,
|
|
|
@@ -695,13 +689,9 @@ describe('UNIT: API', function () {
|
|
|
assert.notOk(this.$compiler.init)
|
|
|
called = true
|
|
|
},
|
|
|
- Test = Vue.extend({ afterCompile: hook }),
|
|
|
- Test2 = Vue.extend({ ready: hook })
|
|
|
+ Test = Vue.extend({ ready: hook })
|
|
|
new Test({ ok: true })
|
|
|
assert.ok(called)
|
|
|
- called = false
|
|
|
- new Test2({ ok: true })
|
|
|
- assert.ok(called)
|
|
|
})
|
|
|
|
|
|
})
|
|
|
@@ -709,15 +699,20 @@ describe('UNIT: API', function () {
|
|
|
describe('beforeDestroy', function () {
|
|
|
|
|
|
it('should be called before a vm is destroyed', function () {
|
|
|
- var called = false
|
|
|
+ var called1 = false,
|
|
|
+ called2 = false
|
|
|
var Test = Vue.extend({
|
|
|
beforeDestroy: function () {
|
|
|
- called = true
|
|
|
+ called1 = true
|
|
|
}
|
|
|
})
|
|
|
var test = new Test()
|
|
|
+ test.$on('hook:beforeDestroy', function () {
|
|
|
+ called2 = true
|
|
|
+ })
|
|
|
test.$destroy()
|
|
|
- assert.ok(called)
|
|
|
+ assert.ok(called1)
|
|
|
+ assert.ok(called2)
|
|
|
})
|
|
|
|
|
|
})
|
|
|
@@ -725,17 +720,62 @@ describe('UNIT: API', function () {
|
|
|
describe('afterDestroy', function () {
|
|
|
|
|
|
it('should be called after a vm is destroyed', function () {
|
|
|
- var called = false,
|
|
|
+ var called1 = false, called2 = false,
|
|
|
Test = Vue.extend({
|
|
|
afterDestroy: function () {
|
|
|
assert.notOk(this.$el.parentNode)
|
|
|
- called = true
|
|
|
+ called1 = true
|
|
|
}
|
|
|
})
|
|
|
var test = new Test()
|
|
|
document.body.appendChild(test.$el)
|
|
|
+ test.$on('hook:afterDestroy', function () {
|
|
|
+ called2 = true
|
|
|
+ })
|
|
|
test.$destroy()
|
|
|
- assert.ok(called)
|
|
|
+ assert.ok(called1)
|
|
|
+ assert.ok(called2)
|
|
|
+ })
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('enteredView', function () {
|
|
|
+
|
|
|
+ it('should be called after enter view', function () {
|
|
|
+ var called1 = false, called2 = false,
|
|
|
+ test = new Vue({
|
|
|
+ enteredView: function () {
|
|
|
+ assert.strictEqual(this.$el.parentNode, document.getElementById('test'))
|
|
|
+ called1 = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ test.$on('hook:enteredView', function () {
|
|
|
+ called2 = true
|
|
|
+ })
|
|
|
+ test.$appendTo('#test')
|
|
|
+ assert.ok(called1)
|
|
|
+ assert.ok(called2)
|
|
|
+ })
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('leftView', function () {
|
|
|
+
|
|
|
+ it('should be called after left view', function () {
|
|
|
+ var called1 = false, called2 = false,
|
|
|
+ test = new Vue({
|
|
|
+ leftView: function () {
|
|
|
+ assert.strictEqual(this.$el.parentNode, null)
|
|
|
+ called1 = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ test.$on('hook:leftView', function () {
|
|
|
+ called2 = true
|
|
|
+ })
|
|
|
+ document.getElementById('test').appendChild(test.$el)
|
|
|
+ test.$remove()
|
|
|
+ assert.ok(called1)
|
|
|
+ assert.ok(called2)
|
|
|
})
|
|
|
|
|
|
})
|
|
|
@@ -743,21 +783,23 @@ describe('UNIT: API', function () {
|
|
|
describe('Hook inheritance', function () {
|
|
|
|
|
|
it('should merge hooks with parent Class', function () {
|
|
|
- var parentCreated = false,
|
|
|
- childCreated = false
|
|
|
+ var called = []
|
|
|
var Parent = Vue.extend({
|
|
|
created: function () {
|
|
|
- parentCreated = true
|
|
|
+ called.push('parent')
|
|
|
}
|
|
|
})
|
|
|
var Child = Parent.extend({
|
|
|
created: function () {
|
|
|
- childCreated = true
|
|
|
+ called.push('child')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ new Child({
|
|
|
+ created: function () {
|
|
|
+ called.push('instance')
|
|
|
}
|
|
|
})
|
|
|
- new Child()
|
|
|
- assert.ok(parentCreated)
|
|
|
- assert.ok(childCreated)
|
|
|
+ assert.deepEqual(called, ['parent', 'child', 'instance'])
|
|
|
})
|
|
|
|
|
|
})
|