Browse Source

test for directive refactor (fix #3848)

dev
Evan You 8 years ago
parent
commit
7570a3c566
  1. 3
      src/core/vdom/helpers.js
  2. 70
      test/unit/features/options/directives.spec.js

3
src/core/vdom/helpers.js

@ -68,7 +68,7 @@ export function getFirstComponentChild (children: ?Array<any>) {
export function mergeVNodeHook (def: Object, hookKey: string, hook: Function, key: string) {
key = key + hookKey
const injectedHash = def.__injected || (def.__injected = {})
if (injectedHash[key]) return
if (!injectedHash[key]) {
injectedHash[key] = true
const oldHook = def[hookKey]
if (oldHook) {
@ -80,6 +80,7 @@ export function mergeVNodeHook (def: Object, hookKey: string, hook: Function, ke
def[hookKey] = hook
}
}
}
export function updateListeners (
on: Object,

70
test/unit/features/options/directives.spec.js

@ -151,6 +151,76 @@ describe('Options directives', () => {
}).then(done)
})
it('should properly handle same node with different directive sets', done => {
const spies = {}
const createSpy = name => (spies[name] = jasmine.createSpy(name))
const vm = new Vue({
data: {
ok: true,
val: 123
},
template: `
<div>
<div v-if="ok" v-test="val" v-test.hi="val"></div>
<div v-if="!ok" v-test.hi="val" v-test2="val"></div>
</div>
`,
directives: {
test: {
bind: createSpy('bind1'),
inserted: createSpy('inserted1'),
update: createSpy('update1'),
componentUpdated: createSpy('componentUpdated1'),
unbind: createSpy('unbind1')
},
test2: {
bind: createSpy('bind2'),
inserted: createSpy('inserted2'),
update: createSpy('update2'),
componentUpdated: createSpy('componentUpdated2'),
unbind: createSpy('unbind2')
}
}
}).$mount()
expect(spies.bind1.calls.count()).toBe(2)
expect(spies.inserted1.calls.count()).toBe(2)
expect(spies.bind2.calls.count()).toBe(0)
expect(spies.inserted2.calls.count()).toBe(0)
vm.ok = false
waitForUpdate(() => {
// v-test with modifier should be updated
expect(spies.update1.calls.count()).toBe(1)
expect(spies.componentUpdated1.calls.count()).toBe(1)
// v-test without modifier should be unbound
expect(spies.unbind1.calls.count()).toBe(1)
// v-test2 should be bound
expect(spies.bind2.calls.count()).toBe(1)
expect(spies.inserted2.calls.count()).toBe(1)
vm.ok = true
}).then(() => {
// v-test without modifier should be bound again
expect(spies.bind1.calls.count()).toBe(3)
expect(spies.inserted1.calls.count()).toBe(3)
// v-test2 should be unbound
expect(spies.unbind2.calls.count()).toBe(1)
// v-test with modifier should be updated again
expect(spies.update1.calls.count()).toBe(2)
expect(spies.componentUpdated1.calls.count()).toBe(2)
vm.val = 234
}).then(() => {
expect(spies.update1.calls.count()).toBe(4)
expect(spies.componentUpdated1.calls.count()).toBe(4)
}).then(done)
})
it('warn non-existent', () => {
new Vue({
template: '<div v-test></div>'

Loading…
Cancel
Save