cesium/packages/engine/Specs/Core/objectToQuerySpec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2022-11-02 03:39:57 +08:00
import { objectToQuery, queryToObject } from "../../index.js";
2020-04-17 08:31:36 +08:00
describe("Core/objectToQuery", function () {
it("can encode data", function () {
const obj = {
key1: "some value",
key2: "a/b",
};
2020-04-17 08:31:36 +08:00
const str = objectToQuery(obj);
expect(str).toEqual("key1=some%20value&key2=a%2Fb");
2020-04-17 08:31:36 +08:00
});
it("can encode arrays of data", function () {
const obj = {
2020-04-17 08:31:36 +08:00
key: ["a", "b"],
};
const str = objectToQuery(obj);
expect(str).toEqual("key=a&key=b");
2020-04-17 08:31:36 +08:00
});
it("runs example code from the documentation", function () {
const str = objectToQuery({
key1: "some value",
2020-04-17 08:31:36 +08:00
key2: "a/b",
key3: ["x", "y"],
});
expect(str).toEqual("key1=some%20value&key2=a%2Fb&key3=x&key3=y");
2020-04-17 08:31:36 +08:00
});
it("can round-trip", function () {
const obj = {
foo: ["bar", "bar2"],
2020-04-17 08:31:36 +08:00
bit: "byte",
};
const obj2 = queryToObject(objectToQuery(obj));
expect(obj2).toEqual(obj);
});
it("can encode blank", function () {
expect(objectToQuery({})).toEqual("");
2020-04-17 08:31:36 +08:00
});
it("requires obj", function () {
expect(function () {
objectToQuery();
}).toThrowDeveloperError();
});
});