-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c6eb47
commit 06f06fb
Showing
5 changed files
with
143 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ language: node_js | |
node_js: | ||
- 6 | ||
- 8 | ||
script: npm test | ||
script: npm run ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,99 @@ | ||
"use strict"; | ||
const customizeURL = require("./"); | ||
const {describe, it} = require("mocha"); | ||
const {expect} = require("chai"); | ||
const {it} = require("mocha"); | ||
|
||
|
||
|
||
it("noSearchParams = true", function() | ||
it("behaves no differently by default", function() | ||
{ | ||
const options = { noSearchParams:true }; | ||
const {IncompleteURL, IncompleteURLSearchParams} = customizeURL(options); | ||
const {IncompleteURL, IncompleteURLSearchParams} = customizeURL(); | ||
|
||
const params = new IncompleteURLSearchParams("?param=value"); | ||
const url = new IncompleteURL("http://hostname?param=value"); | ||
|
||
expect(url).to.not.have.property("searchParams"); | ||
expect(params).to.have.property("sort"); | ||
expect(url).to.have.property("searchParams"); | ||
expect(url.searchParams).to.have.property("sort"); | ||
|
||
expect(params[Symbol.toStringTag]).to.equal("URLSearchParams"); | ||
expect(url[Symbol.toStringTag]).to.equal("URL"); | ||
|
||
expect(Array.from(params)).to.deep.equal([ ["param","value"] ]); | ||
expect(Array.from(url.searchParams)).to.deep.equal([ ["param","value"] ]); | ||
|
||
params.append("param", "value2"); | ||
const iteration = []; | ||
for (let param of params) iteration.push(param); | ||
expect(iteration).to.deep.equal([ ["param","value"], ["param","value2"] ]); | ||
expect(params.toString()).to.equal("param=value¶m=value2") | ||
|
||
expect(() => url.searchParams = params).to.throw(TypeError); | ||
|
||
url.search = ""; | ||
expect(Array.from(url.searchParams)).to.deep.equal([]); | ||
|
||
url.searchParams.set("param", "value"); | ||
expect(url.search).to.equal("?param=value"); | ||
|
||
url.searchParams.delete("param"); | ||
expect(url.search).to.equal(""); | ||
|
||
url.search = "?p2=value2&p1=value&p2=value1"; | ||
url.searchParams.sort(); | ||
expect(url.search).to.equal("?p1=value&p2=value2&p2=value1"); | ||
expect(url.href).to.equal("http://hostname/?p1=value&p2=value2&p2=value1"); | ||
|
||
url.href = "http://hostname2/?new"; | ||
expect(Array.from(url.searchParams)).to.deep.equal([ ["new",""] ]); | ||
|
||
url.pathname = "/path/to"; | ||
expect(url.href).to.equal("http://hostname2/path/to?new"); | ||
|
||
expect(new IncompleteURL(url)).to.be.an.instanceOf(IncompleteURL); | ||
expect(new IncompleteURL("/path/", url)).to.be.an.instanceOf(IncompleteURL); | ||
expect(new IncompleteURLSearchParams(params)).to.be.an.instanceOf(IncompleteURLSearchParams); | ||
}); | ||
|
||
|
||
|
||
describe("options", function() | ||
{ | ||
it("noSearchParams = true", function() | ||
{ | ||
const options = { noSearchParams:true }; | ||
const {IncompleteURL, IncompleteURLSearchParams} = customizeURL(options); | ||
|
||
const url = new IncompleteURL("http://hostname?param=value"); | ||
|
||
expect(url).to.not.have.property("searchParams"); | ||
}); | ||
|
||
|
||
|
||
it("noSort = true", function() | ||
{ | ||
const options = { noSort:true }; | ||
const {IncompleteURL, IncompleteURLSearchParams} = customizeURL(options); | ||
|
||
const params = new IncompleteURLSearchParams("?param=value"); | ||
const url = new IncompleteURL("http://hostname?param=value"); | ||
|
||
expect(params).to.not.have.property("sort"); | ||
expect(url.searchParams).to.not.have.property("sort"); | ||
}); | ||
|
||
|
||
|
||
it("all options true", function() | ||
{ | ||
const options = { noSearchParams:true, noSort:true }; | ||
const {IncompleteURL, IncompleteURLSearchParams} = customizeURL(options); | ||
|
||
const params = new IncompleteURLSearchParams("?param=value"); | ||
const url = new IncompleteURL("http://hostname?param=value"); | ||
|
||
expect(params).to.not.have.property("sort"); | ||
expect(url).to.not.have.property("searchParams"); | ||
}); | ||
}); |