import { URLSearchParams } from "../../utility/algorithm/url-search-params";
describe('URLSearchParams tests', () => {
test('URLSearchParams.handleAppend should add the new value to the tail of the `params` and update the url', () => {
// !!! https://ddzy.github.io/login?name=ddzy&age=21&isSelf=true
url: 'https://ddzy.github.io/login?name=ddzy&age=21&isSelf=true&skill=programmer',
const usp = new URLSearchParams({});
for (const [i, v] of received.entries()) {
const __this__ = usp.handleAppend(v.key, v.value);
const { url, params } = usp.state;
expect(__this__ instanceof URLSearchParams).toBeTruthy();
expect(url).toBe(expected[i].url);
expect(params).toEqual(expected[i].params);
test('URLSearchParams.handleDelete should remove the special `key` from url and params', () => {
url: 'https://ddzy.github.io/login?name=ddzy&isSelf=true',
const usp = new URLSearchParams({});
for (const [i, v] of received.entries()) {
const __this__ = usp.handleDelete(v);
const { url, params } = usp.state;
expect(__this__ instanceof URLSearchParams).toBeTruthy();
expect(url).toBe(expected[i].url);
expect(params).toEqual(expected[i].params);
test('URLSearchParams.handleGet should received the `key` and return the value of this key', () => {
const usp = new URLSearchParams({});
for (const [i, v] of received.entries()) {
const result = usp.handleGet(v);
expect(result).toBe(expected[i]);
test('URLSearchParams.handleGetAll should return all of the params liked `[["name", "ddzy"], ...]`', () => {
const usp = new URLSearchParams({});
const result = usp.handleGetAll();
for (const [i, v] of result.entries()) {
expect(v[0]).toBe(expected[i][0]);
expect(v[1]).toBe(expected[i][1]);
test('URLSearchParams.handleHas should return `true` if the params has its own property that received', () => {
const usp = new URLSearchParams({});
for (const [i, v] of received.entries()) {
const result = usp.handleHas(v);
expect(result).toBe(expected[i]);
test('URLSearchParams.handleSet should set all of the new value to the key which was received', () => {
url: 'https://ddzy.github.io/login?name=duanzhaoyang&age=21&isSelf=true',
url: 'https://ddzy.github.io/login?name=duanzhaoyang&age=50&isSelf=true',
const usp = new URLSearchParams({});
for (const [i, v] of received.entries()) {
const __this__ = usp.handleSet(v.key, v.value);
const { url, params } = usp.state;
expect(__this__ instanceof URLSearchParams).toBeTruthy();
expect(url).toBe(expected[i].url);
expect(params).toEqual(expected[i].params);
test('URLSearchParams.handleKeys should return the `keys-collection` of the params', () => {
const usp = new URLSearchParams({});
const result = usp.handleKeys();
for (const [i, v] of expected.entries()) {
expect(v).toBe(result[i]);
test('URLSearchParams.handleValues should return the `values-collection` of the params', () => {
const usp = new URLSearchParams({});
const result = usp.handleValues();
for (const [i, v] of expected.entries()) {
expect(v).toBe(result[i]);
test('URLSearchParams.iterator should being called by the `iterator`', () => {
const usp = new URLSearchParams({});
for (const [key, value] of (usp.state.params as any)) {
expect(key).toBe(expected[count][0]);
expect(value).toBe(expected[count][1]);