Skip to content

Commit eff7066

Browse files
sobolevnTheAlexLichter
authored andcommitted
feat: marks // links as external
1 parent 806d893 commit eff7066

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default {
55
// Quite useful if you want to bind a link dynamically and don't want to have it clicked and styled when not bound
66
const isExternal = props => !props.to ||
77
props.to.startsWith('http') ||
8+
props.to.startsWith('//') ||
89
props.external
910

1011
return isExternal(props)

test/VueLink.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ describe('VueLink', () => {
7878

7979
expect(wrapper.html()).toBe('<a href="https://example.com/"><div>Hi</div></a>')
8080
})
81+
it('does trigger external on // link', () => {
82+
const wrapper = mount(VueLink, {
83+
localVue,
84+
attachToDocument: true,
85+
stubs: {
86+
RouterLink: RouterLinkStub
87+
},
88+
context: {
89+
props: {
90+
to: '//example.com/'
91+
}
92+
},
93+
slots: {
94+
default: '<div>Hi</div>'
95+
}
96+
})
97+
98+
expect(wrapper.isVueInstance()).toBe(true)
99+
expect(wrapper.contains(RouterLinkStub)).toBe(false)
100+
101+
expect(wrapper.html()).toBe('<a href="//example.com/"><div>Hi</div></a>')
102+
})
81103
it('does trigger external on external prop set', () => {
82104
const wrapper = mount(VueLink, {
83105
localVue,

0 commit comments

Comments
 (0)