You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vitepress/__tests__/unit/client/theme-default/support/utils.test.ts

34 lines
1.1 KiB

import {
ensureStartingSlash,
isLinkExternal
} from 'client/theme-default/support/utils'
describe('client/theme-default/utils', () => {
describe('ensureStartingSlash', () => {
test('it adds slash to the beginning of the given path', () => {
expect(ensureStartingSlash('path')).toBe('/path')
expect(ensureStartingSlash('path/nested')).toBe('/path/nested')
expect(ensureStartingSlash('/path')).toBe('/path')
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)
})
})
})