Skip to content

Commit

Permalink
Use jest-matchers for assertions instead of expect
Browse files Browse the repository at this point in the history
  • Loading branch information
skovhus committed Jul 19, 2017
1 parent 8d98aec commit e97509b
Show file tree
Hide file tree
Showing 36 changed files with 197 additions and 245 deletions.
2 changes: 1 addition & 1 deletion modules/__tests__/BrowserHistory-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import expect from 'expect'
import expect from 'jest-matchers'
import createHistory from '../createBrowserHistory'
import { canUseDOM, supportsHistory } from '../DOMUtils'
import * as TestSequences from './TestSequences'
Expand Down
2 changes: 1 addition & 1 deletion modules/__tests__/HashHistory-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import expect from 'expect'
import expect from 'jest-matchers'
import createHistory from '../createHashHistory'
import { canUseDOM, supportsGoWithoutReloadUsingHash } from '../DOMUtils'
import * as TestSequences from './TestSequences'
Expand Down
26 changes: 13 additions & 13 deletions modules/__tests__/LocationUtils-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import expect from 'expect'
import expect from 'jest-matchers'
import { createLocation } from '../LocationUtils'

describe('createLocation', () => {
describe('with a full path', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('/the/path?the=query#the-hash')).toMatch({
expect(createLocation('/the/path?the=query#the-hash')).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: '#the-hash'
Expand All @@ -15,7 +15,7 @@ describe('createLocation', () => {

describe('given as an object', () => {
it('has the correct properties', () => {
expect(createLocation({ pathname: '/the/path', search: '?the=query', hash: '#the-hash' })).toMatch({
expect(createLocation({ pathname: '/the/path', search: '?the=query', hash: '#the-hash' })).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: '#the-hash'
Expand All @@ -27,7 +27,7 @@ describe('createLocation', () => {
describe('with a relative path', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('the/path?the=query#the-hash')).toMatch({
expect(createLocation('the/path?the=query#the-hash')).toMatchObject({
pathname: 'the/path',
search: '?the=query',
hash: '#the-hash'
Expand All @@ -37,7 +37,7 @@ describe('createLocation', () => {

describe('given as an object', () => {
it('has the correct properties', () => {
expect(createLocation({ pathname: 'the/path', search: '?the=query', hash: '#the-hash' })).toMatch({
expect(createLocation({ pathname: 'the/path', search: '?the=query', hash: '#the-hash' })).toMatchObject({
pathname: 'the/path',
search: '?the=query',
hash: '#the-hash'
Expand All @@ -49,7 +49,7 @@ describe('createLocation', () => {
describe('with a path with no pathname', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('?the=query#the-hash')).toMatch({
expect(createLocation('?the=query#the-hash')).toMatchObject({
pathname: '/',
search: '?the=query',
hash: '#the-hash'
Expand All @@ -59,7 +59,7 @@ describe('createLocation', () => {

describe('given as an object', () => {
it('has the correct properties', () => {
expect(createLocation({ search: '?the=query', hash: '#the-hash' })).toMatch({
expect(createLocation({ search: '?the=query', hash: '#the-hash' })).toMatchObject({
pathname: '/',
search: '?the=query',
hash: '#the-hash'
Expand All @@ -71,7 +71,7 @@ describe('createLocation', () => {
describe('with a path with no search', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('/the/path#the-hash')).toMatch({
expect(createLocation('/the/path#the-hash')).toMatchObject({
pathname: '/the/path',
search: '',
hash: '#the-hash'
Expand All @@ -81,7 +81,7 @@ describe('createLocation', () => {

describe('given as an object', () => {
it('has the correct properties', () => {
expect(createLocation({ pathname: '/the/path', hash: '#the-hash' })).toMatch({
expect(createLocation({ pathname: '/the/path', hash: '#the-hash' })).toMatchObject({
pathname: '/the/path',
search: '',
hash: '#the-hash'
Expand All @@ -93,7 +93,7 @@ describe('createLocation', () => {
describe('with a path with no hash', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('/the/path?the=query')).toMatch({
expect(createLocation('/the/path?the=query')).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: ''
Expand All @@ -103,7 +103,7 @@ describe('createLocation', () => {

describe('given as an object', () => {
it('has the correct properties', () => {
expect(createLocation({ pathname: '/the/path', search: '?the=query' })).toMatch({
expect(createLocation({ pathname: '/the/path', search: '?the=query' })).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: ''
Expand Down Expand Up @@ -134,12 +134,12 @@ describe('createLocation', () => {
describe('key', () => {
it('has a key property if a key is provided', () => {
const location = createLocation('/the/path', undefined, 'key')
expect(location).toIncludeKey('key')
expect(Object.keys(location)).toContain('key')
})

it('has no key property if no key is provided', () => {
const location = createLocation('/the/path')
expect(location).toExcludeKey('key')
expect(Object.keys(location)).not.toContain('key')
})
})
})
8 changes: 4 additions & 4 deletions modules/__tests__/TestSequences/BackButtonTransitionHook.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import expect from 'expect'
import expect from 'jest-matchers'
import execSteps from './execSteps'

export default (history, done) => {
let unblock, hookWasCalled = false
const steps = [
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

history.push('/home')
},
(location, action) => {
expect(action).toBe('PUSH')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/home'
})

Expand All @@ -25,7 +25,7 @@ export default (history, done) => {
},
(location, action) => {
expect(action).toBe('POP')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

Expand Down
6 changes: 3 additions & 3 deletions modules/__tests__/TestSequences/BlockEverything.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import expect from 'expect'
import expect from 'jest-matchers'
import execSteps from './execSteps'

export default (history, done) => {
const steps = [
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

const unblock = history.block()

history.push('/home')

expect(history.location).toMatch({
expect(history.location).toMatchObject({
pathname: '/'
})

Expand Down
4 changes: 2 additions & 2 deletions modules/__tests__/TestSequences/BlockPopWithoutListening.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import expect from 'expect'
import expect from 'jest-matchers'

export default (history, done) => {
expect(history.location).toMatch({
expect(history.location).toMatchObject({
pathname: '/'
})

Expand Down
10 changes: 5 additions & 5 deletions modules/__tests__/TestSequences/DenyGoBack.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import expect from 'expect'
import expect from 'jest-matchers'
import execSteps from './execSteps'

export default (history, done) => {
let unblock
const steps = [
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

history.push('/home')
},
(location, action) => {
expect(action).toBe('PUSH')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/home'
})

unblock = history.block(nextLocation => {
expect(nextLocation).toMatch({
expect(nextLocation).toMatchObject({
pathname: '/'
})

Expand All @@ -29,7 +29,7 @@ export default (history, done) => {
},
(location, action) => {
expect(action).toBe('PUSH')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/home'
})

Expand Down
12 changes: 6 additions & 6 deletions modules/__tests__/TestSequences/DenyGoForward.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import expect from 'expect'
import expect from 'jest-matchers'
import execSteps from './execSteps'

export default (history, done) => {
let unblock
const steps = [
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

history.push('/home')
},
(location, action) => {
expect(action).toBe('PUSH')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/home'
})

history.goBack()
},
(location, action) => {
expect(action).toBe('POP')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

unblock = history.block(nextLocation => {
expect(nextLocation).toMatch({
expect(nextLocation).toMatchObject({
pathname: '/home'
})

Expand All @@ -37,7 +37,7 @@ export default (history, done) => {
},
(location, action) => {
expect(action).toBe('POP')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

Expand Down
8 changes: 4 additions & 4 deletions modules/__tests__/TestSequences/DenyPush.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import expect from 'expect'
import expect from 'jest-matchers'
import execSteps from './execSteps'

export default (history, done) => {
const steps = [
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

const unblock = history.block(nextLocation => {
expect(nextLocation).toMatch({
expect(nextLocation).toMatchObject({
pathname: '/home'
})

Expand All @@ -18,7 +18,7 @@ export default (history, done) => {

history.push('/home')

expect(history.location).toMatch({
expect(history.location).toMatchObject({
pathname: '/'
})

Expand Down
8 changes: 4 additions & 4 deletions modules/__tests__/TestSequences/GoBack.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import expect from 'expect'
import expect from 'jest-matchers'
import execSteps from './execSteps'

export default (history, done) => {
const steps = [
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

history.push('/home')
},
(location, action) => {
expect(action).toEqual('PUSH')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/home'
})

history.goBack()
},
(location, action) => {
expect(action).toEqual('POP')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})
}
Expand Down
10 changes: 5 additions & 5 deletions modules/__tests__/TestSequences/GoForward.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import expect from 'expect'
import expect from 'jest-matchers'
import execSteps from './execSteps'

export default (history, done) => {
const steps = [
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

history.push('/home')
},
(location, action) => {
expect(action).toEqual('PUSH')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/home'
})

history.goBack()
},
(location, action) => {
expect(action).toEqual('POP')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

history.goForward()
},
(location, action) => {
expect(action).toEqual('POP')
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/home'
})
}
Expand Down
6 changes: 3 additions & 3 deletions modules/__tests__/TestSequences/HashChangeTransitionHook.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import expect from 'expect'
import expect from 'jest-matchers'
import execSteps from './execSteps'

export default (history, done) => {
let unblock, hookWasCalled = false
const steps = [
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/'
})

Expand All @@ -16,7 +16,7 @@ export default (history, done) => {
window.location.hash = 'something-new'
},
(location) => {
expect(location).toMatch({
expect(location).toMatchObject({
pathname: '/',
hash: '#something-new'
})
Expand Down
Loading

0 comments on commit e97509b

Please sign in to comment.