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__/client/theme-default/utils.spec.ts

42 lines
1.9 KiB

import * as Utils from 'client/theme-default/utils'
describe('client/theme-default/utils', () => {
describe('ensureStartingSlash', () => {
it('should add slash to the beginning of the given path', () => {
expect(Utils.ensureStartingSlash('path')).toBe('/path')
expect(Utils.ensureStartingSlash('path/nested')).toBe('/path/nested')
expect(Utils.ensureStartingSlash('/path')).toBe('/path')
expect(Utils.ensureStartingSlash('/path/nested')).toBe('/path/nested')
})
})
describe('ensureEndingSlash', () => {
it('should add slash to the end of the given path', () => {
expect(Utils.ensureEndingSlash('path')).toBe('path/')
expect(Utils.ensureEndingSlash('path/nested')).toBe('path/nested/')
expect(Utils.ensureEndingSlash('path/')).toBe('path/')
expect(Utils.ensureEndingSlash('path/nested/')).toBe('path/nested/')
expect(Utils.ensureEndingSlash('path/page.html')).toBe('path/page.html')
})
})
describe('removeExtention', () => {
it('removes `.md` or `.html` extention from the path', () => {
expect(Utils.removeExtention('/')).toBe('/')
expect(Utils.removeExtention('index')).toBe('/')
expect(Utils.removeExtention('index.md')).toBe('/')
expect(Utils.removeExtention('index.html')).toBe('/')
expect(Utils.removeExtention('/index')).toBe('/')
expect(Utils.removeExtention('/index.md')).toBe('/')
expect(Utils.removeExtention('/index.html')).toBe('/')
expect(Utils.removeExtention('path')).toBe('path')
expect(Utils.removeExtention('path.md')).toBe('path')
expect(Utils.removeExtention('path.html')).toBe('path')
expect(Utils.removeExtention('path/')).toBe('path/')
expect(Utils.removeExtention('path/nested.md')).toBe('path/nested')
expect(Utils.removeExtention('path/nested.html')).toBe('path/nested')
expect(Utils.removeExtention('path/nested/index')).toBe('path/nested/')
})
})
})