Sort keys in createSearch + add tests

This commit is contained in:
Michael Jackson
2018-05-25 20:22:59 -04:00
parent 121ea62cb8
commit a8471ed950
2 changed files with 26 additions and 12 deletions

View File

@ -0,0 +1,15 @@
const createSearch = require("../createSearch");
describe("createSearch", () => {
it("omits the trailing = for empty string values", () => {
expect(createSearch({ a: "a", b: "" })).toEqual("?a=a&b");
});
it("sorts keys", () => {
expect(createSearch({ b: "b", a: "a", c: "c" })).toEqual("?a=a&b=b&c=c");
});
it("returns an empty string when there are no params", () => {
expect(createSearch({})).toEqual("");
});
});