|
|
|
|
@ -1,4 +1,7 @@
|
|
|
|
|
import { ensureStartingSlash } from 'client/theme-default/support/utils'
|
|
|
|
|
import {
|
|
|
|
|
ensureStartingSlash,
|
|
|
|
|
isLinkExternal
|
|
|
|
|
} from 'client/theme-default/support/utils'
|
|
|
|
|
|
|
|
|
|
describe('client/theme-default/utils', () => {
|
|
|
|
|
describe('ensureStartingSlash', () => {
|
|
|
|
|
@ -9,4 +12,22 @@ describe('client/theme-default/utils', () => {
|
|
|
|
|
expect(ensureStartingSlash('/path/nested')).toBe('/path/nested')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('isLinkExternal', () => {
|
|
|
|
|
test('it detects external links by default', () => {
|
|
|
|
|
expect(isLinkExternal('https://vite.dev')).toBe(true)
|
|
|
|
|
expect(isLinkExternal('/guide/')).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('it treats _blank targets as external by default', () => {
|
|
|
|
|
expect(isLinkExternal('/guide/', '_blank')).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('it allows callers to override external detection', () => {
|
|
|
|
|
expect(isLinkExternal('https://cn.vite.dev', undefined, false)).toBe(
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
expect(isLinkExternal('/guide/', undefined, true)).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|