Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/router / __tests__ / OneRouter.updated.test.ts
Size: Mime:
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
  })
})