-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupUrlParams.test.js
44 lines (39 loc) · 1.65 KB
/
setupUrlParams.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const setupUrlParams = require('./setupUrlParams')
describe('setupUrlParams', () => {
describe('with mock getPath function', () => {
it('should match with matching path from function', () => {
const mockGetPath = () => '/fake-id/list'
const useUrlParamsWithMock = setupUrlParams(mockGetPath)
const params = useUrlParamsWithMock('/:account/list')
expect(params).toEqual(
expect.objectContaining({ account: 'fake-id' })
)
})
it('should not match with non-matching path from function', () => {
const mockGetPath = () => '/fake-id/list'
const useUrlParamsWithMock = setupUrlParams(mockGetPath)
const params = useUrlParamsWithMock('/:account/page')
expect(params).toEqual({ matches: false })
})
it('should match with matching path with no variables from function', () => {
const mockGetPath = () => '/list'
const useUrlParamsWithMock = setupUrlParams(mockGetPath)
const params = useUrlParamsWithMock('/list')
expect(params).toEqual({ matches: true })
})
it('should return variables with no provided path', () => {
const mockGetPath = () => '/list?id=3110'
const useUrlParamsWithMock = setupUrlParams(mockGetPath)
const params = useUrlParamsWithMock()
expect(params).toEqual(
expect.objectContaining({ id: '3110' })
)
})
it('should not match with non-matching path with no variables from function', () => {
const mockGetPath = () => '/list'
const useUrlParamsWithMock = setupUrlParams(mockGetPath)
const params = useUrlParamsWithMock('/page')
expect(params).toEqual({ matches: false })
})
})
})