web-utils-super
Version:
前端函数库
63 lines (61 loc) • 2.3 kB
JavaScript
describe('Url API:', function () {
const utils = window['web-utils-super']
describe('#parseQueryString()', function () {
it(`utils.parseQueryString('https://www.baidu.com/s?wd=%E7%99%BE%E5%BA%A6&rsv_spt=10') deepEqual '{
wd: '百度',
rsv_spt: '10'
}' should return true`, function () {
let url = 'https://www.baidu.com/s?wd=%E7%99%BE%E5%BA%A6&rsv_spt=10'
assert.deepEqual(utils.parseQueryString(url), {
wd: '百度',
rsv_spt: '10'
})
})
it(`utils.parseQueryString('www.baidu.com?a=123&b=%26') deepEqual '{
a: '123',
b: '&'
}' should return true`, function () {
let url = 'www.baidu.com?a=123&b=%26'
assert.deepEqual(utils.parseQueryString(url), {
a: '123',
b: '&'
})
})
it(`utils.parseQueryString('') deepEqual '{}' should return true`, function () {
let url = ''
assert.deepEqual(utils.parseQueryString(url), {})
})
})
describe('#stringfyQueryString()', function () {
it(`utils.stringfyQueryString({
wd: '百度',
rsv_spt: '10'
}) === 'https://www.baidu.com/s?wd=%E7%99%BE%E5%BA%A6&rsv_spt=10' should return true`, function () {
let param = {
wd: '百度',
rsv_spt: '10'
}
assert(utils.stringfyQueryString(param) === 'wd=%E7%99%BE%E5%BA%A6&rsv_spt=10')
})
})
describe('#getQueryString()', function () {
it(`utils.getQueryString('route', 'http://localhost:8083/#/Home/vehicleProhibitionManagement?route=6') === '6' should return true`, function () {
console.log(
utils.getQueryString(
'route',
'http://localhost:8083/#/Home/vehicleProhibitionManagement?route=6'
)
)
assert(
utils.getQueryString(
'route',
'http://localhost:8083/#/Home/vehicleProhibitionManagement?route=6'
) === '6'
)
})
it(`utils.getQueryString('id', 'https://baidu.com?id=12345') === '12345' should return true`, function () {
console.log(utils.getQueryString('id', 'https://baidu.com?id=12345'))
assert(utils.getQueryString('id', 'https://baidu.com?id=12345') === '12345')
})
})
})