Skip to content

Commit 1ce8d56

Browse files
committed
fix unit test for #147
1 parent ab4b388 commit 1ce8d56

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/directives/link.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function (Vue) {
2525
if (e.metaKey || e.ctrlKey || e.shiftKey) return
2626
// don't redirect when preventDefault called
2727
if (e.defaultPrevented) return
28-
28+
// don't redirect on right click
2929
if (e.button !== 0) return
3030

3131
if (this.el.tagName === 'A') {
@@ -41,10 +41,9 @@ export default function (Vue) {
4141
el = el.parentNode
4242
}
4343
if (!el || el.tagName !== 'A' || !el.href) return
44-
4544
if (sameOrigin(el)) {
4645
e.preventDefault()
47-
router.go(el.href)
46+
router.go(el.pathname)
4847
}
4948
}
5049
}

test/unit/specs/core.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ describe('Core', function () {
293293
})
294294

295295
it('v-link delegate', function (done) {
296+
// Safari and PhantomJS only propagates events if the
297+
// element is in the DOM!
298+
document.body.appendChild(el)
296299
router = new Router({ abstract: true })
297300
router.map({
298301
'/': {
@@ -318,14 +321,15 @@ describe('Core', function () {
318321
router.go('/foo')
319322
nextTick(function () {
320323
var wrap = el.querySelector('#wrap')
321-
var e = document.createEvent('HTMLEvents')
322-
// target is read-only
323-
e.target = wrap.querySelector('a')
324+
var e = document.createEvent('Events')
324325
e.initEvent('click', true, true)
325-
wrap.dispatchEvent(e)
326+
e.button = 0
327+
var target = wrap.querySelector('a')
328+
target.dispatchEvent(e)
326329
nextTick(function () {
327330
var text = router.app.$el.textContent
328331
expect(text).toBe('Home')
332+
document.body.removeChild(el)
329333
done()
330334
})
331335
})

0 commit comments

Comments
 (0)