--- /dev/null
+import { stripBase } from '../../src/history/common'
+import { createDom } from '../utils'
+
+describe('History Location Utils', () => {
+ beforeAll(() => {
+ createDom()
+ })
+
+ describe('stripBase', () => {
+ it('returns the pathname if no base', () => {
+ expect(stripBase('', '')).toBe('')
+ expect(stripBase('/', '')).toBe('/')
+ expect(stripBase('/thing', '')).toBe('/thing')
+ })
+
+ it('returns the pathname without the base', () => {
+ expect(stripBase('/base', '/base')).toBe('/')
+ expect(stripBase('/base/', '/base')).toBe('/')
+ expect(stripBase('/base/foo', '/base')).toBe('/foo')
+ })
+ })
+})
basic(browser) {
browser
.url(baseURL)
+ // TODO: move this test to a different spec
+ .assert.urlEquals(baseURL + '/')
.waitForElementVisible('#app', 1000)
.click('li:nth-child(3) a')
.assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
// check initial visit
- .url(baseURL + '/encoding/documents/%E2%82%ACuro')
+ .url(baseURL + '/documents/%E2%82%ACuro')
.waitForElementVisible('#app', 1000)
.assert.containsText('#fullPath', '/documents/%E2%82%ACuro')
.assert.containsText('#path', '/documents/%E2%82%ACuro')
- // .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
- // .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
+ .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
- browser
- .getText('#params', function(res) {
- this.assert.equal(res.value, JSON.stringify({ id: '€uro' }, null, 2))
- console.log(res.state)
- })
.end()
},
}
* @param base base to strip off
*/
export function stripBase(pathname: string, base: string): string {
- return (
- (base && pathname.indexOf(base) === 0 && pathname.replace(base, '')) ||
- pathname
- )
+ if (!base || pathname.indexOf(base) !== 0) return pathname
+ return pathname.replace(base, '') || '/'
}
export function normalizeHistoryLocation(