moy-router
Version:
Give a solution for moy-dom router management.
163 lines (151 loc) • 3.15 kB
JavaScript
import parseRoute from 'src/utils/parseRoute'
describe('test for parseRoute with String type', () => {
test('route without query and hash', () => {
expect(parseRoute('/murakami')).toEqual({
pathname: '/murakami',
})
})
test('route with query', () => {
expect(parseRoute('/murakami?a=1')).toEqual({
pathname: '/murakami?a=1',
query: {
a: '1',
},
})
})
test('route with hash', () => {
expect(parseRoute('/murakami#a')).toEqual({
pathname: '/murakami#a',
hash: 'a',
})
})
test('route with query and hash', () => {
expect(parseRoute('/murakami?a=1#a')).toEqual({
pathname: '/murakami?a=1#a',
query: {
a: '1',
},
hash: 'a',
})
})
})
describe('test for parseRoute with Object type', () => {
test('test route without params, query and hash', () => {
expect(parseRoute({
pathname: '/murakami',
})).toEqual({
pathname: '/murakami',
})
})
test('test route just with params', () => {
expect(parseRoute({
pathname: '/users/:name',
params: {
name: 'murakami',
},
})).toEqual({
pathname: '/users/murakami',
params: {
name: 'murakami',
},
})
})
test('test route just with query', () => {
expect(parseRoute({
pathname: '/murakami',
query: {
a: '1',
b: '2',
},
})).toEqual({
pathname: '/murakami?a=1&b=2',
query: {
a: '1',
b: '2',
},
})
})
test('test route just with hash', () => {
expect(parseRoute({
pathname: '/murakami',
hash: 'a',
})).toEqual({
pathname: '/murakami#a',
hash: 'a',
})
})
test('test route with params and query', () => {
expect(parseRoute({
pathname: '/users/:name',
params: {
name: 'murakami',
},
query: {
a: '1'
},
})).toEqual({
pathname: '/users/murakami?a=1',
params: {
name: 'murakami',
},
query: {
a: '1'
},
})
})
test('test route with params and hash', () => {
expect(parseRoute({
pathname: '/users/:name',
params: {
name: 'murakami',
},
hash: 'a',
})).toEqual({
pathname: '/users/murakami#a',
params: {
name: 'murakami',
},
hash: 'a',
})
})
test('test route with query and hash', () => {
expect(parseRoute({
pathname: '/murakami',
query: {
a: '',
b: '2',
},
hash: 'a',
})).toEqual({
pathname: '/murakami?a=&b=2#a',
query: {
a: '',
b: '2',
},
hash: 'a',
})
})
test('test route with params, query and hash', () => {
expect(parseRoute({
pathname: 'users/:name',
params: {
name: 'murakami',
},
query: {
a: '1',
b: '2',
},
hash: 'a',
})).toEqual({
pathname: 'users/murakami?a=1&b=2#a',
params: {
name: 'murakami',
},
query: {
a: '1',
b: '2',
},
hash: 'a',
})
})
})