-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
2 changed files
with
70 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var util = require('../src/util'); | ||
|
||
describe("urlSlice", function() { | ||
var { urlSlice } = util; | ||
|
||
it("should handle urls with query string", function() { | ||
|
||
var result = urlSlice("/this/is/sample?q1=val&q2=val3"); | ||
expect(result.url).toEqual("/this/is/sample"); | ||
expect(result.queryStr).toEqual("q1=val&q2=val3"); | ||
|
||
}); | ||
|
||
it("should handle urls with hash", function() { | ||
|
||
var result = urlSlice("/this/is/sample#q1=val&q2=val3"); | ||
expect(result.url).toEqual("/this/is/sample"); | ||
expect(result.hashStr).toEqual("q1=val&q2=val3"); | ||
|
||
}); | ||
|
||
it("should handle urls with both query string and hash", function() { | ||
|
||
var result = urlSlice("/this/is/sample?q1=val&q2=val3#q2=val2&q3=val4"); | ||
expect(result.url).toEqual("/this/is/sample"); | ||
expect(result.queryStr).toEqual("q1=val&q2=val3"); | ||
expect(result.hashStr).toEqual("q2=val2&q3=val4"); | ||
|
||
}); | ||
|
||
it("should only slice the hash string after the first fragment identifier if there are multiple", function() { | ||
|
||
var result = urlSlice("/this/is/sample?q1=val&q2=val3#q1=val#q2=val3"); | ||
expect(result.hashStr).toEqual("q1=val#q2=val3"); | ||
|
||
}); | ||
|
||
it("should only slice the query string after the first query params identifier if there are multiple", function() { | ||
|
||
var result = urlSlice("/this/is/sample?q1=val&q2=val3?q1=val#q2=val3"); | ||
expect(result.queryStr).toEqual("q1=val&q2=val3?q1=val"); | ||
|
||
}); | ||
|
||
it("should slice the hash string correctly if a query params identifier appears in the fragment string", function() { | ||
|
||
var result = urlSlice("/this/is/sample#q1=val&q2=val3&q1=val?q2=val3"); | ||
expect(result.hashStr).toEqual("q1=val&q2=val3&q1=val?q2=val3"); | ||
|
||
}); | ||
}); |