Commit e0949a93 authored by MrMan's avatar MrMan

Add util test, URI.js for browser & node contexts

parent 043e23b5
......@@ -30,6 +30,7 @@ System.config({
"react-router": "npm:react-router@1.0.0",
"reflux": "npm:reflux@0.3.0",
"reflux-state-mixin": "npm:reflux-state-mixin@0.4.5",
"uri.js": "bower:uri.js@1.17.0",
"bower:pure@0.6.0": {
"css": "github:systemjs/plugin-css@0.1.19"
},
......
import _ from "lodash";
import fetch from "vendor/fetch";
import Constants from "./constants";
import URI from "uri.js";
// Error patterns for Tinder's FB auth request redirect
const re_login_resp_err = /error=([^&]+)/;
......@@ -30,9 +31,9 @@ export const UNIT_PLURALS = {
* @returns a URL object
*/
export function generateURLWithQueryParams(base, params) {
let url = new URL(base);
_.each(params, (val, key) => url.searchParams.append(key, val));
return url;
let url = new URI(base);
_.each(params, (val, key) => url.addQuery(key, val));
return url.toString();
}
......
......@@ -14,7 +14,8 @@
"react": "npm:react@^0.14.0",
"react-dom": "npm:react-dom@^0.14.0",
"react-router": "npm:react-router@^1.0.0",
"reflux": "npm:reflux@^0.3.0"
"reflux": "npm:reflux@^0.3.0",
"uri.js": "bower:uri.js@^1.17.0"
},
"devDependencies": {
"babel": "npm:babel-core@^5.8.24",
......
import System from "systemjs";
import "../config";
import "should";
import _ from "lodash";
class URL {
constructor(something) {
console.log("URL created?");
}
}
const TEST_URL = "http://nowhere.com/api";
describe("JS Utils", () => {
// Ensure that the generated constants export contains the functions we expect
it("Should generate a URL with query parameters properly", (done) => {
System.import("./js/util")
.then(util => {
let generatedUrl = util.generateURLWithQueryParams(TEST_URL, {string: "yep", number: 1});
generatedUrl.should.containEql("string=yep");
generatedUrl.should.containEql(TEST_URL);
generatedUrl.should.containEql("number=1");
done();
})
.catch(done);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment