Skip to content

Commit b292e46

Browse files
committed
fix: fixed param2Obj.spec.js
1 parent 4958db1 commit b292e46

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

tests/unit/utils/param2Obj.spec.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
/**
2-
* @param {string} url
3-
* @returns {Object}
4-
*/
5-
export function param2Obj(url) {
6-
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
7-
if (!search) {
8-
return {}
9-
}
10-
const obj = {}
11-
const searchArr = search.split('&')
12-
searchArr.forEach(v => {
13-
const index = v.indexOf('=')
14-
if (index !== -1) {
15-
const name = v.substring(0, index)
16-
const val = v.substring(index + 1, v.length)
17-
obj[name] = val
18-
}
1+
import { param2Obj } from '@/utils/index.js'
2+
describe('Utils:param2Obj', () => {
3+
const url = 'https://github.com/PanJiaChen/vue-element-admin?name=bill&age=29&sex=1&field=dGVzdA==&key=%E6%B5%8B%E8%AF%95'
4+
5+
it('param2Obj test', () => {
6+
expect(param2Obj(url)).toEqual({
7+
name: 'bill',
8+
age: '29',
9+
sex: '1',
10+
field: window.btoa('test'),
11+
key: '测试'
12+
})
1913
})
20-
return obj
21-
}
14+
})

0 commit comments

Comments
 (0)