Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #182

Closed
wants to merge 3 commits into from
Closed

V2 #182

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions modules/__tests__/BrowserHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { supportsHistory } from '../DOMUtils'
import createBrowserHistory from '../createBrowserHistory'
import describeInitialLocation from './describeInitialLocation'
import describeTransitions from './describeTransitions'
import describePushState from './describePushState'
import describePush from './describePush'
import describeReplaceState from './describeReplaceState'
import describeReplace from './describeReplace'
import describePopState from './describePopState'
import describePop from './describePop'
import describeHashSupport from './describeHashSupport'
import describeBasename from './describeBasename'
import describeQueries from './describeQueries'
Expand All @@ -20,11 +18,9 @@ describe('browser history', function () {
if (supportsHistory()) {
describeInitialLocation(createBrowserHistory)
describeTransitions(createBrowserHistory)
describePushState(createBrowserHistory)
describePush(createBrowserHistory)
describeReplaceState(createBrowserHistory)
describeReplace(createBrowserHistory)
describePopState(createBrowserHistory)
describePop(createBrowserHistory)
describeHashSupport(createBrowserHistory)
describeBasename(createBrowserHistory)
describeQueries(createBrowserHistory)
Expand All @@ -33,11 +29,9 @@ describe('browser history', function () {
describe.skip(null, function () {
describeInitialLocation(createBrowserHistory)
describeTransitions(createBrowserHistory)
describePushState(createBrowserHistory)
describePush(createBrowserHistory)
describeReplaceState(createBrowserHistory)
describeReplace(createBrowserHistory)
describePopState(createBrowserHistory)
describePop(createBrowserHistory)
describeHashSupport(createBrowserHistory)
describeBasename(createBrowserHistory)
describeQueries(createBrowserHistory)
Expand Down
10 changes: 3 additions & 7 deletions modules/__tests__/HashHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { supportsGoWithoutReloadUsingHash, supportsHistory } from '../DOMUtils'
import createHashHistory from '../createHashHistory'
import describeInitialLocation from './describeInitialLocation'
import describeTransitions from './describeTransitions'
import describePushState from './describePushState'
import describePush from './describePush'
import describeReplaceState from './describeReplaceState'
import describeReplace from './describeReplace'
import describePopState from './describePopState'
import describePop from './describePop'
import describeQueryKey from './describeQueryKey'
import describeBasename from './describeBasename'
import describeQueries from './describeQueries'
Expand All @@ -21,18 +19,16 @@ describe('hash history', function () {

describeInitialLocation(createHashHistory)
describeTransitions(createHashHistory)
describePushState(createHashHistory)
describePush(createHashHistory)
describeReplaceState(createHashHistory)
describeReplace(createHashHistory)
describeBasename(createHashHistory)
describeQueries(createHashHistory)

if (supportsHistory()) {
describePopState(createHashHistory)
describePop(createHashHistory)
} else {
describe.skip(null, function () {
describePopState(createHashHistory)
describePop(createHashHistory)
})
}

Expand Down
20 changes: 10 additions & 10 deletions modules/__tests__/Location-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@ import { POP } from '../Actions'

describe('a location', function () {
it('knows its pathname', function () {
let location = createLocation('/home?the=query#the-hash')
const location = createLocation('/home?the=query#the-hash')
expect(location.pathname).toEqual('/home')
})

it('knows its search string', function () {
let location = createLocation('/home?the=query#the-hash')
const location = createLocation('/home?the=query#the-hash')
expect(location.search).toEqual('?the=query')
})

it('knows its hash', function () {
let location = createLocation('/home?the=query#the-hash')
const location = createLocation('/home?the=query#the-hash')
expect(location.hash).toEqual('#the-hash')
})

it('compensates if the location is fully qualified', function () {
let location = createLocation('https://example.com/home')
const location = createLocation('https://example.com/home')
expect(location.pathname).toEqual('/home')
})

it('does not strip URL-like strings in the query', function () {
let location = createLocation('/home?redirect=https://example.com/')
const location = createLocation('/home?redirect=https://example.com/')
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('?redirect=https://example.com/')
})

it('has null state by default', function () {
let location = createLocation()
const location = createLocation()
expect(location.state).toBe(null)
})

it('uses pop navigation by default', function () {
let location = createLocation()
const location = createLocation()
expect(location.action).toBe(POP)
})

it('has a null key by default', function () {
let location = createLocation()
const location = createLocation()
expect(location.key).toBe(null)
})

Expand All @@ -52,15 +52,15 @@ describe('a location', function () {
})

it('has a key by default', function () {
let location = history.createLocation()
const location = history.createLocation()
expect(location.key).toExist()
})
})
})

describe('creating a location with an object', function () {
it('puts the pathname, search, and hash in the proper order', function () {
let location = createLocation({
const location = createLocation({
pathname: '/the/path',
search: '?the=query',
hash: '#the-hash'
Expand Down
4 changes: 0 additions & 4 deletions modules/__tests__/MemoryHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import expect from 'expect'
import createMemoryHistory from '../createMemoryHistory'
import describeInitialLocation from './describeInitialLocation'
import describeTransitions from './describeTransitions'
import describePushState from './describePushState'
import describePush from './describePush'
import describeReplaceState from './describeReplaceState'
import describeReplace from './describeReplace'
import describeBasename from './describeBasename'
import describeQueries from './describeQueries'
Expand All @@ -13,9 +11,7 @@ import describeGo from './describeGo'
describe('memory history', function () {
describeInitialLocation(createMemoryHistory)
describeTransitions(createMemoryHistory)
describePushState(createMemoryHistory)
describePush(createMemoryHistory)
describeReplaceState(createMemoryHistory)
describeReplace(createMemoryHistory)
describeBasename(createMemoryHistory)
describeQueries(createMemoryHistory)
Expand Down
74 changes: 12 additions & 62 deletions modules/__tests__/describeBasename.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,9 @@ function describeBasename(createHistory) {
unlisten()
})

describe('in pushState', function () {
it('works', function (done) {
let steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
expect(location.state).toEqual(null)
expect(location.action).toEqual(POP)
expect(location.basename).toEqual('')

history.pushState({ the: 'state' }, '/home')
},
function (location) {
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('')
expect(location.state).toEqual({ the: 'state' })
expect(location.action).toEqual(PUSH)
expect(location.basename).toEqual('/base/url')
}
]

unlisten = history.listen(execSteps(steps, done))
})
})

describe('in push', function () {
it('works with string', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand All @@ -71,7 +46,7 @@ function describeBasename(createHistory) {
})

it('works with object', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand Down Expand Up @@ -109,34 +84,9 @@ function describeBasename(createHistory) {
})
})

describe('in replaceState', function () {
it('works', function (done) {
let steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
expect(location.state).toEqual(null)
expect(location.action).toEqual(POP)
expect(location.basename).toEqual('')

history.replaceState({ the: 'state' }, '/home')
},
function (location) {
expect(location.pathname).toEqual('/home')
expect(location.search).toEqual('')
expect(location.state).toEqual({ the: 'state' })
expect(location.action).toEqual(REPLACE)
expect(location.basename).toEqual('/base/url')
}
]

unlisten = history.listen(execSteps(steps, done))
})
})

describe('in replace', function () {
it('works with string', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand All @@ -159,7 +109,7 @@ function describeBasename(createHistory) {
})

it('works with object', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand Down Expand Up @@ -214,10 +164,10 @@ function describeBasename(createHistory) {
})
})

describe('basename through <base href>', () => {
describe('basename through <base href>', function () {
let history, unlisten, base

before('add base element', () => {
before('add base element', function () {
base = document.createElement('base')
base.href = '/base/url'
document.head.appendChild(base)
Expand All @@ -227,25 +177,25 @@ function describeBasename(createHistory) {
history = useBasename(createHistory)()
})

describe('in createPath', () => {
describe('in createPath', function () {
it('works', function () {
expect(
history.createPath('/the/path')
).toEqual('/base/url/the/path')
})
})

describe('in createHref', () => {
describe('in createHref', function () {
it('works', function () {
expect(
stripHash(history.createHref('/the/path'))
).toEqual('/base/url/the/path')
})
})

describe('in push', () => {
describe('in push', function () {
it('works', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand All @@ -271,12 +221,12 @@ function describeBasename(createHistory) {
})
})

afterEach(() => {
afterEach(function () {
if (unlisten)
unlisten()
})

after(() => {
after(function () {
document.head.removeChild(base)
})

Expand Down
4 changes: 2 additions & 2 deletions modules/__tests__/describeGo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function describeGo(createHistory) {

describe('back', function () {
it('calls change listeners with the previous location', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand Down Expand Up @@ -51,7 +51,7 @@ function describeGo(createHistory) {

describe('forward', function () {
it('calls change listeners with the next location', function (done) {
let steps = [
const steps = [
function (location) {
expect(location.pathname).toEqual('/')
expect(location.search).toEqual('')
Expand Down
25 changes: 25 additions & 0 deletions modules/__tests__/describePop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function describePop(createHistory) {
describe('when a listenBefore hook is added', function () {
let history, unlisten

beforeEach(function () {
history = createHistory()
history.push('/home')
})

afterEach(function () {
if (unlisten)
unlisten()
})

it('is called when browser navigation is used', function (done) {
unlisten = history.listenBefore(function () {
done()
})

window.history.back()
})
})
}

export default describePop
Loading