Repository URL to install this package:
|
Version:
6.1.0 ▾
|
import 'jest'
import { OneRouterToRuleThemAll, oneRouter, setConfig } from '../src'
describe('oneRouter/updated', () => {
it('should work for .origin & protocol', () => {
global.window = {
location: {
// for some reason in window, it has `https:` :o
protocol: 'http',
host: 'localhost.eh.com',
origin: 'http://localhost.eh.com',
href: 'http://localhost.eh.com/@@mock',
pathname: '@@mock',
search: '',
reload() {
// use this to mock reload
},
pushState() {
// use this to mock pushstate
},
},
}
const twoRouter = new OneRouterToRuleThemAll()
expect(twoRouter.origin).toEqual('http://localhost.eh.com')
delete global.window
})
it('should work for .forceUpdate', () => {
global.window = {
location: {
href: 'http://localhost.eh.com/@@mock',
pathname: '@@mock',
search: '',
reload() {
// use this to mock reload
},
pushState() {
// use this to mock pushstate
},
},
}
const twoRouter = new OneRouterToRuleThemAll()
expect(twoRouter.full.includes('@@mock')).toBe(true)
// expect(twoRouter.pathname.includes('@@mock')).toBe(true)
// absolute
twoRouter.forceUpdate('http://localhost.eh.com/forced')
expect(twoRouter.full.includes('forced')).toBe(true)
// expect(twoRouter.pathname.includes('forced')).toBe(true)
// reset
twoRouter.forceUpdate('http://localhost.eh.com/@@mock')
expect(twoRouter.full.includes('@@mock')).toBe(true)
// expect(twoRouter.pathname.includes('@@mock')).toBe(true)
// relative
twoRouter.forceUpdate('/forced')
expect(twoRouter.full.includes('forced')).toBe(true)
// expect(twoRouter.pathname.includes('forced')).toBe(true)
delete global.window
})
})