can-route
Advanced tools
Comparing version 4.4.7 to 4.4.8
139
can-route.js
@@ -0,11 +1,14 @@ | ||
// # can-route.js | ||
// Manage browser history and client state by synchronizing | ||
// the window.location.hash with an observable. | ||
"use strict"; | ||
/*jshint -W079 */ | ||
var Bind = require("can-bind"); | ||
var queues = require("can-queues"); | ||
var Observation = require('can-observation'); | ||
var Observation = require("can-observation"); | ||
var namespace = require('can-namespace'); | ||
var devLog = require('can-log/dev/dev'); | ||
var canReflect = require('can-reflect'); | ||
var canSymbol = require('can-symbol'); | ||
var namespace = require("can-namespace"); | ||
var devLog = require("can-log/dev/dev"); | ||
var canReflect = require("can-reflect"); | ||
var canSymbol = require("can-symbol"); | ||
var makeCompute = require("can-simple-observable/make-compute/make-compute"); | ||
@@ -22,5 +25,9 @@ var RouteData = require("./src/routedata"); | ||
var isWebWorker = require('can-globals/is-web-worker/is-web-worker'); | ||
var isBrowserWindow = require('can-globals/is-browser-window/is-browser-window'); | ||
var isWebWorker = require("can-globals/is-web-worker/is-web-worker"); | ||
var isBrowserWindow = require("can-globals/is-browser-window/is-browser-window"); | ||
// ## hashchangeObservable | ||
// `hashchangeObservable` is an instance of `Hashchange`, instances of | ||
// `Hashchange` are two-way bound to `window.location.hash` once the | ||
// instances have a listener. | ||
var hashchangeObservable = new Hashchange(); | ||
@@ -32,11 +39,7 @@ bindingProxy.bindings.hashchange = hashchangeObservable; | ||
// ## route.js | ||
// `can-route` | ||
// _Helps manage browser history (and client state) by synchronizing the | ||
// `window.location.hash` with a `Map`._ | ||
function canRoute(url, defaults){ | ||
// ## canRoute | ||
function canRoute(url, defaults) { | ||
//!steal-remove-start | ||
if(typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') { | ||
devLog.warn('Call route.register(url,defaults) instead of calling route(url, defaults)'); | ||
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") { | ||
devLog.warn("Call route.register(url,defaults) instead of calling route(url, defaults)"); | ||
} | ||
@@ -49,5 +52,3 @@ //!steal-remove-end | ||
// Helper methods used for matching routes. | ||
// ## Helper Functions | ||
// A ~~throttled~~ debounced function called multiple times will only fire once the | ||
@@ -57,3 +58,3 @@ // timer runs down. Each call resets the timer. | ||
// A dummy events object used to dispatch url change events on. | ||
var currentRuleObservable = new Observation(function canRoute_matchedRoute(){ | ||
var currentRuleObservable = new Observation(function canRoute_matchedRoute() { | ||
var url = bindingProxy.call("can.getValue"); | ||
@@ -63,3 +64,3 @@ return canRoute.rule(url); | ||
// ### updateUrl | ||
// If the `route.data` changes, update the hash. | ||
@@ -88,2 +89,3 @@ // Using `.serialize()` retrieves the raw data contained in the `observable`. | ||
// ### updateRouteData | ||
// Deparameterizes the portion of the hash of interest and assign the | ||
@@ -113,3 +115,3 @@ // values to the `route.data` removing existing values no longer in the hash. | ||
*/ | ||
Object.defineProperty(canRoute,"routes",{ | ||
Object.defineProperty(canRoute, "routes", { | ||
/** | ||
@@ -141,10 +143,12 @@ * @property {Object} routes | ||
}); | ||
Object.defineProperty(canRoute,"defaultBinding",{ | ||
get: function(){ | ||
// ## canRoute.defaultBinding | ||
Object.defineProperty(canRoute, "defaultBinding", { | ||
get: function() { | ||
return bindingProxy.defaultBinding; | ||
}, | ||
set: function(newVal){ | ||
set: function(newVal) { | ||
bindingProxy.defaultBinding = newVal; | ||
var observable = bindingProxy.bindings[bindingProxy.defaultBinding]; | ||
if(observable) { | ||
if (observable) { | ||
bindingProxy.urlDataObservable.value = observable; | ||
@@ -154,7 +158,9 @@ } | ||
}); | ||
Object.defineProperty(canRoute,"urlData",{ | ||
get: function(){ | ||
// ## canRoute.urlData | ||
Object.defineProperty(canRoute, "urlData", { | ||
get: function() { | ||
return bindingProxy.urlDataObservable.value; | ||
}, | ||
set: function(newVal){ | ||
set: function(newVal) { | ||
canRoute._teardown(); | ||
@@ -166,8 +172,11 @@ bindingProxy.urlDataObservable.value = newVal; | ||
canReflect.assignMap(canRoute, { | ||
// ## canRoute.param | ||
param: routeParam, | ||
// ## canRoute.deparam | ||
deparam: routeDeparam, | ||
map: function(data){ | ||
// ## canRoute.map | ||
map: function(data) { | ||
//!steal-remove-start | ||
if(typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') { | ||
devLog.warn('Set route.data directly instead of calling route.map'); | ||
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") { | ||
devLog.warn("Set route.data directly instead of calling route.map"); | ||
} | ||
@@ -178,7 +187,7 @@ //!steal-remove-end | ||
// ## canRoute.start | ||
start: function (val) { | ||
if (val !== true) { | ||
canRoute._setup(); | ||
if(isBrowserWindow() || isWebWorker()) { | ||
if (isBrowserWindow() || isWebWorker()) { | ||
// We can't use updateRouteData because we want to merge the route data | ||
@@ -199,2 +208,3 @@ // into .data | ||
}, | ||
// ## canRoute.url | ||
url: urlHelpers.url, | ||
@@ -247,3 +257,3 @@ link: urlHelpers.link, | ||
//!steal-remove-start | ||
if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') { | ||
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") { | ||
bindingOptions.updateChildName = "can-route.updateRouteData"; | ||
@@ -277,5 +287,5 @@ bindingOptions.updateParentName = "can-route.updateUrl"; | ||
register: registerRoute.register, | ||
rule: function(url){ | ||
rule: function(url) { | ||
var rule = routeDeparam.getRule(url); | ||
if(rule) { | ||
if (rule) { | ||
return rule.route; | ||
@@ -289,3 +299,3 @@ } | ||
var bindToCanRouteData = function(name, args) { | ||
var bindToCanRouteData = function (name, args) { | ||
if (!canRoute.data[name]) { | ||
@@ -297,6 +307,6 @@ return canRoute.data.addEventListener.apply(canRoute.data, args); | ||
['addEventListener','removeEventListener','bind', 'unbind', 'on', 'off'].forEach(function(name) { | ||
["addEventListener","removeEventListener","bind", "unbind", "on", "off"].forEach(function(name) { | ||
// exposing all internal eventQueue evt’s to canRoute | ||
canRoute[name] = function(eventName, handler) { | ||
if (eventName === '__url') { | ||
if (eventName === "__url") { | ||
return bindingProxy.call("can.onValue", handler ); | ||
@@ -308,3 +318,3 @@ } | ||
['delegate', 'undelegate', 'removeAttr', 'compute', '_get', '___get', 'each'].forEach(function (name) { | ||
["delegate", "undelegate", "removeAttr", "compute", "_get", "___get", "each"].forEach(function (name) { | ||
canRoute[name] = function () { | ||
@@ -318,14 +328,15 @@ // `delegate` and `undelegate` require | ||
var routeData; | ||
var setRouteData = function(data){ | ||
var routeData, | ||
serializedObservation, | ||
serializedCompute; | ||
function setRouteData(data) { | ||
routeData = data; | ||
return routeData; | ||
}; | ||
var serializedObservation; | ||
var serializedCompute; | ||
} | ||
Object.defineProperty(canRoute,"serializedObservation", { | ||
get: function(){ | ||
if(!serializedObservation) { | ||
serializedObservation = new Observation(function canRoute_data_serialized(){ | ||
Object.defineProperty(canRoute, "serializedObservation", { | ||
get: function() { | ||
if (!serializedObservation) { | ||
serializedObservation = new Observation(function canRoute_data_serialized() { | ||
return canReflect.serialize( canRoute.data ); | ||
@@ -337,5 +348,5 @@ }); | ||
}); | ||
Object.defineProperty(canRoute,"serializedCompute", { | ||
get: function(){ | ||
if(!serializedCompute) { | ||
Object.defineProperty(canRoute, "serializedCompute", { | ||
get: function() { | ||
if (!serializedCompute) { | ||
serializedCompute = makeCompute(canRoute.serializedObservation); | ||
@@ -348,5 +359,5 @@ } | ||
var viewModelSymbol = canSymbol.for("can.viewModel"); | ||
Object.defineProperty(canRoute,"data", { | ||
get: function(){ | ||
if(routeData) { | ||
Object.defineProperty(canRoute, "data", { | ||
get: function() { | ||
if (routeData) { | ||
return routeData; | ||
@@ -358,10 +369,10 @@ } else { | ||
set: function(data) { | ||
if( canReflect.isConstructorLike(data) ){ | ||
if ( canReflect.isConstructorLike(data) ) { | ||
data = new data(); | ||
} | ||
if(data && data[viewModelSymbol] !== undefined) { | ||
if (data && data[viewModelSymbol] !== undefined) { | ||
data = data[viewModelSymbol]; | ||
} | ||
// if it’s a map, we make it always set strings for backwards compat | ||
if( "attr" in data ) { | ||
if ( "attr" in data ) { | ||
setRouteData( stringCoercingMapDecorator(data) ); | ||
@@ -374,14 +385,14 @@ } else { | ||
canRoute.attr = function(prop, value){ | ||
canRoute.attr = function(prop, value) { | ||
console.warn("can-route: can-route.attr is deprecated. Use methods on can-route.data instead."); | ||
if("attr" in canRoute.data) { | ||
if ("attr" in canRoute.data) { | ||
return canRoute.data.attr.apply(canRoute.data, arguments); | ||
} else { | ||
if(arguments.length > 1) { | ||
if (arguments.length > 1) { | ||
canReflect.setKeyValue(canRoute.data, prop, value); | ||
return canRoute.data; | ||
} else if(typeof prop === 'object') { | ||
} else if (typeof prop === "object") { | ||
canReflect.assignDeep(canRoute.data,prop); | ||
return canRoute.data; | ||
} else if(arguments.length === 1){ | ||
} else if (arguments.length === 1) { | ||
return canReflect.getKeyValue(canRoute.data, prop); | ||
@@ -388,0 +399,0 @@ } else { |
{ | ||
"name": "can-route", | ||
"version": "4.4.7", | ||
"version": "4.4.8", | ||
"description": "Observable front-end application routing for CanJS.", | ||
@@ -70,3 +70,3 @@ "homepage": "https://canjs.com/doc/can-route.html", | ||
"steal": "^2.0.0", | ||
"steal-qunit": "^1.0.1", | ||
"steal-qunit": "^2.0.0", | ||
"steal-tools": "^1.1.2", | ||
@@ -73,0 +73,0 @@ "test-saucelabs": "0.0.6", |
"use strict"; | ||
var canReflect = require('can-reflect'); | ||
var canReflect = require("can-reflect"); | ||
var canSymbol = require("can-symbol"); | ||
@@ -8,22 +8,23 @@ var SimpleObservable = require("can-simple-observable"); | ||
canReflect.setName(urlDataObservable,"route.urlData"); | ||
canReflect.setName(urlDataObservable, "route.urlData"); | ||
var bindingProxy = { | ||
defaultBinding: null, | ||
urlDataObservable: urlDataObservable, | ||
bindings: {}, | ||
call: function(){ | ||
var args = canReflect.toArray(arguments), | ||
prop = args.shift(), | ||
binding = urlDataObservable.value; | ||
if(binding === null) { | ||
throw new Error("there is no current binding!!!"); | ||
} | ||
var method = binding[prop.indexOf("can.") === 0 ? canSymbol.for(prop) : prop]; | ||
if (method.apply) { | ||
return method.apply(binding, args); | ||
} else { | ||
return method; | ||
} | ||
} | ||
defaultBinding: null, | ||
urlDataObservable: urlDataObservable, | ||
bindings: {}, | ||
call: function() { | ||
var args = canReflect.toArray(arguments), | ||
prop = args.shift(), | ||
binding = urlDataObservable.value; | ||
if (binding === null) { | ||
throw new Error("there is no current binding!!!"); | ||
} | ||
var method = binding[prop.indexOf("can.") === 0 ? canSymbol.for(prop) : prop]; | ||
if (method.apply) { | ||
return method.apply(binding, args); | ||
} else { | ||
return method; | ||
} | ||
} | ||
}; | ||
module.exports = bindingProxy; |
"use strict"; | ||
var deparam = require('can-deparam'); | ||
var deparam = require("can-deparam"); | ||
var canReflect = require("can-reflect"); | ||
@@ -8,3 +8,8 @@ | ||
var decode = function(str){ | ||
// ## Helper Functions | ||
// ### decode | ||
// Restore escaped HTML from its URI value. | ||
// It isn't compatable with named character references (`©`, etc). | ||
function decode(str) { | ||
try { | ||
@@ -15,30 +20,30 @@ return decodeURIComponent(str); | ||
} | ||
}; | ||
} | ||
// ### toURLFragment | ||
// If the `root` ends with `/` and the url starts with it, remove `/`. | ||
// TODO: I'm not totally sure this belongs here. This might be shifted to can-route-pushstate. | ||
function toURLFragment(url){ | ||
var root =bindingProxy.call("root"); | ||
// if the root ends with `/` and the url starts with it, remove / | ||
if (root.lastIndexOf("/") === root.length - 1 && url.indexOf("/") === 0) { | ||
url = url.substr(1); | ||
} | ||
function toURLFragment(url) { | ||
var root = bindingProxy.call("root"); | ||
if (root.lastIndexOf("/") === root.length - 1 && url.indexOf("/") === 0) { | ||
url = url.substr(1); | ||
} | ||
return url; | ||
} | ||
function canRoute_getRule(url){ | ||
// ### canRoute_getRule | ||
function canRoute_getRule(url) { | ||
url = toURLFragment(url); | ||
// See if the url matches any routes by testing it against the `route.test` `RegExp`. | ||
// By comparing the URL length the most specialized route that matches is used. | ||
var route = { | ||
length: -1 | ||
}; | ||
canReflect.eachKey(register.routes, function (temp, name) { | ||
if (temp.test.test(url) && temp.length > route.length) { | ||
route = temp; | ||
} | ||
}); | ||
// If a route was matched. | ||
if (route.length > -1) { | ||
// See if the url matches any routes by testing it against the `route.test` `RegExp`. | ||
// By comparing the URL length the most specialized route that matches is used. | ||
var route = { | ||
length: -1 | ||
}; | ||
canReflect.eachKey(register.routes, function(temp, name) { | ||
if (temp.test.test(url) && temp.length > route.length) { | ||
route = temp; | ||
} | ||
}); | ||
// If a route was matched. | ||
if (route.length > -1) { | ||
return route; | ||
@@ -50,5 +55,5 @@ } | ||
var route = canRoute_getRule(url), | ||
querySeparator =bindingProxy.call("querySeparator"), | ||
paramsMatcher =bindingProxy.call("paramsMatcher"); | ||
var route = canRoute_getRule(url), | ||
querySeparator = bindingProxy.call("querySeparator"), | ||
paramsMatcher = bindingProxy.call("paramsMatcher"); | ||
@@ -58,30 +63,29 @@ url = toURLFragment(url); | ||
// If a route was matched. | ||
if (route) { | ||
if (route) { | ||
// Since `RegExp` backreferences are used in `route.test` (parens) | ||
// the parts will contain the full matched string and each variable (back-referenced) value. | ||
var parts = url.match(route.test), | ||
// Start will contain the full matched string; parts contain the variable values. | ||
start = parts.shift(), | ||
// The remainder will be the `&key=value` list at the end of the URL. | ||
remainder = url.substr(start.length - (parts[parts.length - 1] === querySeparator ? 1 : 0)), | ||
// If there is a remainder and it contains a `&key=value` list deparam it. | ||
obj = (remainder && paramsMatcher.test(remainder)) ? deparam(remainder.slice(1)) : {}; | ||
var // Since `RegExp` backreferences are used in `route.test` (parens) | ||
// the parts will contain the full matched string and each variable (back-referenced) value. | ||
parts = url.match(route.test), | ||
// Start will contain the full matched string; parts contain the variable values. | ||
start = parts.shift(), | ||
// The remainder will be the `&key=value` list at the end of the URL. | ||
remainder = url.substr(start.length - (parts[parts.length - 1] === querySeparator ? 1 : 0)), | ||
// If there is a remainder and it contains a `&key=value` list deparam it. | ||
obj = (remainder && paramsMatcher.test(remainder)) ? deparam(remainder.slice(1)) : {}; | ||
// Add the default values for this route. | ||
obj = canReflect.assignDeep(canReflect.assignDeep({}, route.defaults), obj); | ||
// Overwrite each of the default values in `obj` with those in | ||
// parts if that part is not empty. | ||
parts.forEach(function (part, i) { | ||
if (part && part !== querySeparator) { | ||
obj[route.names[i]] = decode(part); | ||
} | ||
}); | ||
return obj; | ||
} | ||
// If no route was matched, it is parsed as a `&key=value` list. | ||
if (url.charAt(0) !== querySeparator) { | ||
url = querySeparator + url; | ||
} | ||
return paramsMatcher.test(url) ? deparam(url.slice(1)) : {}; | ||
// Add the default values for this route. | ||
obj = canReflect.assignDeep(canReflect.assignDeep({}, route.defaults), obj); | ||
// Overwrite each of the default values in `obj` with those in | ||
// parts if that part is not empty. | ||
parts.forEach(function (part, i) { | ||
if (part && part !== querySeparator) { | ||
obj[route.names[i]] = decode(part); | ||
} | ||
}); | ||
return obj; | ||
} | ||
// If no route was matched, it is parsed as a `&key=value` list. | ||
if (url.charAt(0) !== querySeparator) { | ||
url = querySeparator + url; | ||
} | ||
return paramsMatcher.test(url) ? deparam(url.slice(1)) : {}; | ||
} | ||
@@ -91,3 +95,2 @@ | ||
module.exports = canRoute_deparam; |
131
src/param.js
"use strict"; | ||
var canReflect = require("can-reflect"); | ||
var param = require('can-param'); | ||
var param = require("can-param"); | ||
@@ -9,2 +9,3 @@ var register = require("./register"); | ||
// ## matchesData | ||
// Checks if a route matches the data provided. If any route variable | ||
@@ -14,10 +15,9 @@ // is not present in the data, the route does not match. If all route | ||
// to allow discerning between general and more specific routes. | ||
var matchesData = function (route, data) { | ||
function matchesData(route, data) { | ||
var count = 0, | ||
i = 0, | ||
defaults = {}; | ||
// look at default values, if they match ... | ||
// Look at default route values, if they match increment count | ||
for (var name in route.defaults) { | ||
if (route.defaults[name] === data[name]) { | ||
// mark as matched | ||
defaults[name] = 1; | ||
@@ -27,3 +27,5 @@ count++; | ||
} | ||
for (; i < route.names.length; i++) { | ||
for (var i = 0; i < route.names.length; i++) { | ||
// If a route name isn't present in data, the route doesn't match. | ||
if (!data.hasOwnProperty(route.names[i])) { | ||
@@ -35,41 +37,42 @@ return -1; | ||
} | ||
} | ||
return count; | ||
}; | ||
} | ||
// ## getMatchedRoute | ||
function getMatchedRoute(data, routeName) { | ||
// Check if the provided data keys match the names in any routes; | ||
// Get the one with the most matches. | ||
var route, | ||
// Need to have at least 1 match. | ||
matches = 0, | ||
matchCount, | ||
propCount = 0; | ||
// Get the one with the most matches. | ||
var route, | ||
// Need to have at least 1 match. | ||
matches = 0, | ||
matchCount, | ||
propCount = 0; | ||
delete data.route; | ||
delete data.route; | ||
canReflect.eachKey(data, function () { | ||
propCount++; | ||
}); | ||
// Otherwise find route. | ||
canReflect.eachKey(register.routes, function (temp, name) { | ||
// best route is the first with all defaults matching | ||
canReflect.eachKey(data, function () { | ||
propCount++; | ||
}); | ||
// Otherwise find route. | ||
canReflect.eachKey(register.routes, function (temp, name) { | ||
// best route is the first with all defaults matching | ||
matchCount = matchesData(temp, data); | ||
if (matchCount > matches) { | ||
route = temp; | ||
matches = matchCount; | ||
} | ||
if (matchCount >= propCount) { | ||
return false; | ||
} | ||
}); | ||
// If we have a route name in our `register` data, and it's | ||
// just as good as what currently matches, use that | ||
if (register.routes[routeName] && matchesData(register.routes[routeName], data) === matches) { | ||
route = register.routes[routeName]; | ||
} | ||
// If this is match... | ||
matchCount = matchesData(temp, data); | ||
if (matchCount > matches) { | ||
route = temp; | ||
matches = matchCount; | ||
} | ||
if (matchCount >= propCount) { | ||
return false; | ||
} | ||
}); | ||
// If we have a route name in our `register` data, and it's | ||
// just as good as what currently matches, use that | ||
if (register.routes[routeName] && matchesData(register.routes[routeName], data) === matches) { | ||
route = register.routes[routeName]; | ||
} | ||
// If this is match... | ||
return route; | ||
@@ -84,30 +87,30 @@ } | ||
cpy = canReflect.assignMap({}, data); | ||
// fall back to legacy :foo RegExp if necessary | ||
matcher = regexps.colon.test(route.route) ? regexps.colon : regexps.curlies; | ||
// Create the url by replacing the var names with the provided data. | ||
// If the default value is found an empty string is inserted. | ||
res = route.route.replace(matcher, function (whole, name) { | ||
delete cpy[name]; | ||
return data[name] === route.defaults[name] ? "" : encodeURIComponent(data[name]); | ||
}) | ||
.replace("\\", ""); | ||
// Remove matching default values | ||
canReflect.eachKey(route.defaults, function (val, name) { | ||
if (cpy[name] === val) { | ||
delete cpy[name]; | ||
} | ||
}); | ||
// The remaining elements of data are added as | ||
// `&` separated parameters to the url. | ||
after = param(cpy); | ||
// if we are paraming for setting the hash | ||
// we also want to make sure the route value is updated | ||
//if (_setRoute) { | ||
// register.matched(route.route); | ||
//} | ||
return res + (after ? bindingProxy.call("querySeparator") + after : ""); | ||
} | ||
// If no route was found, there is no hash URL, only paramters. | ||
return canReflect.size(data) === 0 ? "" :bindingProxy.call("querySeparator") + param(data); | ||
cpy = canReflect.assignMap({}, data); | ||
// fall back to legacy :foo RegExp if necessary | ||
matcher = regexps.colon.test(route.route) ? regexps.colon : regexps.curlies; | ||
// Create the url by replacing the var names with the provided data. | ||
// If the default value is found an empty string is inserted. | ||
res = route.route.replace(matcher, function (whole, name) { | ||
delete cpy[name]; | ||
return data[name] === route.defaults[name] ? "" : encodeURIComponent(data[name]); | ||
}) | ||
.replace("\\", ""); | ||
// Remove matching default values | ||
canReflect.eachKey(route.defaults, function (val, name) { | ||
if (cpy[name] === val) { | ||
delete cpy[name]; | ||
} | ||
}); | ||
// The remaining elements of data are added as | ||
// `&` separated parameters to the url. | ||
after = param(cpy); | ||
// if we are paraming for setting the hash | ||
// we also want to make sure the route value is updated | ||
//if (_setRoute) { | ||
// register.matched(route.route); | ||
//} | ||
return res + (after ? bindingProxy.call("querySeparator") + after : ""); | ||
} | ||
// If no route was found, there is no hash URL, only paramters. | ||
return canReflect.size(data) === 0 ? "" :bindingProxy.call("querySeparator") + param(data); | ||
} | ||
@@ -114,0 +117,0 @@ |
"use strict"; | ||
module.exports = { | ||
curlies: /\{\s*([\w.]+)\s*\}/g, | ||
colon: /\:([\w.]+)/g | ||
curlies: /\{\s*([\w.]+)\s*\}/g, | ||
colon: /\:([\w.]+)/g | ||
}; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var dev = require('can-log/dev/dev'); | ||
var dev = require("can-log/dev/dev"); | ||
@@ -11,4 +11,4 @@ var bindingProxy = require("./binding-proxy"); | ||
var diff = require('can-diff/list/list'); | ||
var diffObject = require('can-diff/map/map'); | ||
var diff = require("can-diff/list/list"); | ||
var diffObject = require("can-diff/map/map"); | ||
var RouteData = require("./routedata"); | ||
@@ -18,96 +18,101 @@ // `RegExp` used to match route variables of the type '{name}'. | ||
// ### removeBackslash | ||
// Removes all backslashes (`\`) from a string. | ||
function removeBackslash(string) { | ||
return string.replace(/\\/g, ""); | ||
} | ||
var removeBackslash = function (str) { | ||
return str.replace(/\\/g, ""); | ||
}; | ||
var wrapQuote = function (str) { | ||
return (str + '') | ||
// ### wrapQuote | ||
// Converts input to a string and readies string for regex | ||
// input by escaping the following special characters: `[ ] ( ) { } \ ^ $ . | ? * +`. | ||
function wrapQuote(string) { | ||
return (string + "") | ||
.replace(/([.?*+\^$\[\]\\(){}|\-])/g, "\\$1"); | ||
}; | ||
} | ||
var RouteRegistry = { | ||
routes: {}, | ||
register: function registerRoute(url, defaults) { | ||
// if route ends with a / and url starts with a /, remove the leading / of the url | ||
var root = bindingProxy.call("root"); | ||
routes: {}, | ||
register: function(url, defaults) { | ||
// If the root ends with a forward slash (`/`) | ||
// and url starts with a forward slash (`/`), remove the leading | ||
// forward slash (`/`) of the url. | ||
var root = bindingProxy.call("root"); | ||
if (root.lastIndexOf("/") === root.length - 1 && | ||
url.indexOf("/") === 0) { | ||
url = url.substr(1); | ||
} | ||
if ( root.lastIndexOf("/") === root.length - 1 && url.indexOf("/") === 0 ) { | ||
url = url.substr(1); | ||
} | ||
defaults = defaults || {}; | ||
// Extract the variable names and replace with `RegExp` that will match | ||
// an atual URL with values. | ||
var names = [], | ||
res, | ||
test = "", | ||
matcher, | ||
lastIndex, | ||
next, | ||
querySeparator = bindingProxy.call("querySeparator"), | ||
matchSlashes = bindingProxy.call("matchSlashes"); | ||
// `matcher` will be a regex | ||
// fall back to legacy `:foo` RegExp if necessary | ||
var matcher; | ||
if (regexps.colon.test(url)) { | ||
//!steal-remove-start | ||
if (process.env.NODE_ENV !== "production") { | ||
dev.warn("update route \"" + url + "\" to \"" + url.replace(regexps.colon, function(name, key) { | ||
return "{" + key + "}"; | ||
}) + "\""); | ||
} | ||
//!steal-remove-end | ||
// fall back to legacy `:foo` RegExp if necessary | ||
if (regexps.colon.test(url)) { | ||
matcher = regexps.colon; | ||
matcher = regexps.colon; | ||
} else { | ||
matcher = regexps.curlies; | ||
} | ||
//!steal-remove-start | ||
if(process.env.NODE_ENV !== 'production') { | ||
dev.warn('update route "' + url + '" to "' + url.replace(regexps.colon, function(name, key) { | ||
return '{' + key + '}'; | ||
}) + '"'); | ||
} | ||
//!steal-remove-end | ||
} else { | ||
matcher = regexps.curlies; | ||
} | ||
lastIndex = matcher.lastIndex = 0; | ||
defaults = defaults || {}; | ||
// res will be something like ["{foo}","foo"] | ||
while (res = matcher.exec(url)) { | ||
names.push(res[1]); | ||
test += removeBackslash(url.substring(lastIndex, matcher.lastIndex - res[0].length)); | ||
// if matchSlashes is false (the default) don't greedily match any slash in the string, assume its part of the URL | ||
next = "\\" + (removeBackslash(url.substr(matcher.lastIndex, 1)) || querySeparator+(matchSlashes? "": "|/")); | ||
// a name without a default value HAS to have a value | ||
// a name that has a default value can be empty | ||
// The `\\` is for string-escaping giving single `\` for `RegExp` escaping. | ||
test += "([^" + next + "]" + (defaults[res[1]] ? "*" : "+") + ")"; | ||
lastIndex = matcher.lastIndex; | ||
} | ||
test += url.substr(lastIndex) | ||
.replace("\\", ""); | ||
// Extract the variable names and replace with `RegExp` that will match | ||
// an actual URL with values. | ||
var lastIndex = matcher.lastIndex = 0, | ||
names = [], | ||
res, | ||
test = "", | ||
next, | ||
querySeparator = bindingProxy.call("querySeparator"), | ||
matchSlashes = bindingProxy.call("matchSlashes"); | ||
//!steal-remove-start | ||
if(process.env.NODE_ENV !== 'production') { | ||
// warn if new route uses same map properties as an existing route | ||
canReflect.eachKey(RouteRegistry.routes, function(r) { | ||
var existingKeys = r.names.concat(Object.keys(r.defaults)).sort(); | ||
var keys = names.concat(Object.keys(defaults)).sort(); | ||
var sameMapKeys = !diff(existingKeys, keys).length; | ||
var sameDefaultValues = !diffObject(r.defaults, defaults).length; | ||
//the regex removes the trailing slash | ||
var matchingRoutesWithoutTrailingSlash = r.route.replace(/\/$/, "") === url.replace(/\/$/, ""); | ||
// res will be something like ["{foo}","foo"] | ||
while (res = matcher.exec(url)) { | ||
names.push(res[1]); | ||
test += removeBackslash(url.substring(lastIndex, matcher.lastIndex - res[0].length)); | ||
// If matchSlashes is false (the default) don't greedily match any slash in the string, assume its part of the URL | ||
next = "\\" + (removeBackslash(url.substr(matcher.lastIndex, 1)) || querySeparator+(matchSlashes? "": "|/")); | ||
// A name without a default value HAS to have a value. | ||
// A name that has a default value can be empty. | ||
// The `\\` is for string-escaping giving single `\` for `RegExp` escaping. | ||
test += "([^" + next + "]" + (defaults[res[1]] ? "*" : "+") + ")"; | ||
lastIndex = matcher.lastIndex; | ||
} | ||
test += removeBackslash(url.substr(lastIndex)); | ||
if (sameMapKeys && sameDefaultValues && !matchingRoutesWithoutTrailingSlash) { | ||
dev.warn('two routes were registered with matching keys:\n' + | ||
'\t(1) route.register("' + r.route + '", ' + JSON.stringify(r.defaults) + ')\n' + | ||
'\t(2) route.register("' + url + '", ' + JSON.stringify(defaults) + ')\n' + | ||
'(1) will always be chosen since it was registered first'); | ||
} | ||
}); | ||
} | ||
//!steal-remove-start | ||
if (process.env.NODE_ENV !== "production") { | ||
// warn if new route uses same map properties as an existing route | ||
canReflect.eachKey(RouteRegistry.routes, function(r) { | ||
var existingKeys = r.names.concat(Object.keys(r.defaults)).sort(), | ||
keys = names.concat(Object.keys(defaults)).sort(), | ||
sameMapKeys = !diff(existingKeys, keys).length, | ||
sameDefaultValues = !diffObject(r.defaults, defaults).length, | ||
//the regex removes the trailing slash | ||
matchingRoutesWithoutTrailingSlash = r.route.replace(/\/$/, "") === url.replace(/\/$/, ""); | ||
if (sameMapKeys && sameDefaultValues && !matchingRoutesWithoutTrailingSlash) { | ||
dev.warn("two routes were registered with matching keys:\n" + | ||
"\t(1) route.register(\"" + r.route + "\", " + JSON.stringify(r.defaults) + ")\n" + | ||
"\t(2) route.register(\"" + url + "\", " + JSON.stringify(defaults) + ")\n" + | ||
"(1) will always be chosen since it was registered first"); | ||
} | ||
}); | ||
} | ||
//!steal-remove-end | ||
// Assign to the instance props | ||
if(this.data instanceof RouteData) { | ||
if (this.data instanceof RouteData) { | ||
var routeData = this.data; | ||
canReflect.eachIndex(names, function(name) { | ||
var type = "string"; | ||
var defaultValue = defaults[name]; | ||
var typeOf = typeof defaultValue; | ||
var type = "string", | ||
defaultValue = defaults[name], | ||
typeOf = typeof defaultValue; | ||
if(defaultValue != null) { | ||
if (defaultValue != null) { | ||
type = typeOf; | ||
@@ -122,21 +127,20 @@ } | ||
// Add route in a form that can be easily figured out. | ||
return RouteRegistry.routes[url] = { | ||
// A regular expression that will match the route when variable values | ||
// are present; i.e. for (`{page}/{type}`) the `RegExp` is `/([\w\.]*)/([\w\.]*)/` which | ||
// will match for any value of `{page}` and `{type}` (word chars or period). | ||
test: new RegExp("^" + test + "($|" + wrapQuote(querySeparator) + ")"), | ||
// The original URL, same as the index for this entry in routes. | ||
route: url, | ||
// An `array` of all the variable names in this route. | ||
names: names, | ||
// Default values provided for the variables. | ||
defaults: defaults, | ||
// The number of parts in the URL separated by `/`. | ||
length: url.split('/') | ||
.length | ||
}; | ||
} | ||
// Add route in a form that can be easily figured out. | ||
return RouteRegistry.routes[url] = { | ||
// A regular expression that will match the route when variable values | ||
// are present; i.e. for (`{page}/{type}`) the `RegExp` is `/([\w\.]*)/([\w\.]*)/` which | ||
// will match for any value of `{page}` and `{type}` (word chars or period). | ||
test: new RegExp("^" + test + "($|" + wrapQuote(querySeparator) + ")"), | ||
// The original URL, same as the index for this entry in routes. | ||
route: url, | ||
// An `array` of all the variable names in this route. | ||
names: names, | ||
// Default values provided for the variables. | ||
defaults: defaults, | ||
// The number of parts in the URL separated by `/`. | ||
length: url.split("/").length | ||
}; | ||
} | ||
}; | ||
module.exports = RouteRegistry; |
var canReflect = require("can-reflect"); | ||
var canSymbol = require("can-symbol"); | ||
// Helper for convert any object (or value) to stringified object (or value) | ||
var stringify = function (obj) { | ||
// Object is array, plain object, Map or List | ||
// # String Coercion Helper Functions | ||
// ## stringify | ||
// Converts an object, array, Map or List to a string. | ||
// It attempts the following flow to convert to a string: | ||
// if `obj` is an object: | ||
// - call `.serialize` on `obj`, if available | ||
// - shallow copy `obj` using `.slice` or `can-reflect.assign` | ||
// - convert each proprety to a string recursively | ||
// else | ||
// - call `.toString` on `obj`, if available. | ||
function stringify(obj) { | ||
if (obj && typeof obj === "object") { | ||
if (obj && typeof obj === "object" && ("serialize" in obj)) { | ||
if ("serialize" in obj) { | ||
obj = obj.serialize(); | ||
// Get array from array-like or shallow-copy object. | ||
} else if (typeof obj.slice === "function") { | ||
obj = obj.slice(); | ||
} else { | ||
// Get array from array-like or shallow-copy object | ||
obj = typeof obj.slice === "function" ? obj.slice() : canReflect.assign({}, obj); | ||
canReflect.assign({}, obj); | ||
} | ||
// Convert each object property or array item into stringified new | ||
canReflect.eachKey(obj, function (val, prop) { | ||
// Convert each object property or array item into a string. | ||
canReflect.eachKey(obj, function(val, prop) { | ||
obj[prop] = stringify(val); | ||
}); | ||
// Object supports toString function | ||
// If `obj` supports `.toString` call it. | ||
} else if (obj !== undefined && obj !== null && (typeof obj.toString === "function" )) { | ||
@@ -24,15 +38,21 @@ obj = obj.toString(); | ||
return obj; | ||
}; | ||
} | ||
// ## stringCoercingMapDecorator | ||
// Coercies the arguments of `can-map.attr` to strings. | ||
// everything in the backing Map is a string | ||
// add type coercion during Map setter to coerce all values to strings so unexpected conflicts don't happen. | ||
// https://github.com/canjs/canjs/issues/2206 | ||
var stringCoercingMapDecorator = function(map) { | ||
var sym = canSymbol.for("can.route.stringCoercingMapDecorator"); | ||
if(!map.attr[sym]) { | ||
var attrSuper = map.attr; | ||
// A proposal to change this behavior is currently open: | ||
// https://github.com/canjs/can-route/issues/125 | ||
function stringCoercingMapDecorator(map) { | ||
var decoratorSymbol = canSymbol.for("can.route.stringCoercingMapDecorator"); | ||
map.attr = function(prop, val) { | ||
var serializable = typeof prop === "string" && | ||
(this.define === undefined || this.define[prop] === undefined || !!this.define[prop].serialize), | ||
if (!map.attr[decoratorSymbol]) { | ||
var attrUndecoratedFunction = map.attr; | ||
map.attr = function(key) { | ||
var serializable = typeof key === "string" && | ||
(this.define === undefined || this.define[key] === undefined || !!this.define[key].serialize), | ||
args; | ||
@@ -46,11 +66,12 @@ | ||
return attrSuper.apply(this, args); | ||
return attrUndecoratedFunction.apply(this, args); | ||
}; | ||
canReflect.setKeyValue(map.attr, sym, true); | ||
canReflect.setKeyValue(map.attr, decoratorSymbol, true); | ||
} | ||
return map; | ||
}; | ||
} | ||
exports.stringCoercingMapDecorator = stringCoercingMapDecorator; | ||
exports.stringify = stringify; |
@@ -6,22 +6,38 @@ "use strict"; | ||
var canReflect = require("can-reflect"); | ||
var string = require('can-string'); | ||
var string = require("can-string"); | ||
// ### formatAttributes | ||
// Creates HTML-like attributes from an object. | ||
// It escapes hyperlink references. | ||
function formatAttributes(props) { | ||
var tags = []; | ||
canReflect.eachKey(props, function(value, name) { | ||
// Converts `"className"` to `"class"`. | ||
var attributeName = name === "className" ? "class" : name, | ||
var makeProps = function (props) { | ||
var tags = []; | ||
canReflect.eachKey(props, function (val, name) { | ||
tags.push((name === 'className' ? 'class' : name) + '="' + | ||
(name === "href" ? val : string.esc(val)) + '"'); | ||
// Escapes `value` if `name` is `"href"`. | ||
attributeValue = name === "href" ? value : string.esc(value); | ||
tags.push(attributeName + "=\"" + attributeValue + "\""); | ||
}); | ||
return tags.join(" "); | ||
}; | ||
var matchCheck = function(source, matcher){ | ||
} | ||
// ### matchCheck | ||
// It recursively compares property values in `matcher` to those in `source`. | ||
// It returns `false` if there's a property in `source` that's not in `matcher`, | ||
// or if the two values aren't loosely equal. | ||
function matchCheck(source, matcher) { | ||
/*jshint eqeqeq:false*/ | ||
for(var prop in source) { | ||
var s = source[prop], | ||
m = matcher[prop]; | ||
if(s && m && typeof s === "object" && typeof matcher === "object") { | ||
return matchCheck(s, m); | ||
for(var property in source) { | ||
var sourceProperty = source[property], | ||
matcherProperty = matcher[property]; | ||
if (sourceProperty && matcherProperty && | ||
typeof sourceProperty === "object" && typeof matcher === "object" | ||
) { | ||
return matchCheck(sourceProperty, matcherProperty); | ||
} | ||
if(s != m) { | ||
if (sourceProperty != matcherProperty) { | ||
return false; | ||
@@ -31,31 +47,34 @@ } | ||
return true; | ||
}; | ||
} | ||
// ### canRoute_url | ||
function canRoute_url(options, merge) { | ||
if (merge) { | ||
var baseOptions = routeDeparam( bindingProxy.call("can.getValue") ); | ||
options = canReflect.assignMap(canReflect.assignMap({}, baseOptions), options); | ||
} | ||
return bindingProxy.call("root") + routeParam(options); | ||
} | ||
if (merge) { | ||
var baseOptions = routeDeparam(bindingProxy.call("can.getValue")); | ||
options = canReflect.assignMap(canReflect.assignMap({}, baseOptions), options); | ||
} | ||
return bindingProxy.call("root") +routeParam(options); | ||
} | ||
module.exports = { | ||
url: canRoute_url, | ||
url: canRoute_url, | ||
link: function canRoute_link(name, options, props, merge) { | ||
return "<a " + makeProps( | ||
canReflect.assignMap({ | ||
href: canRoute_url(options, merge) | ||
}, props)) + ">" + name + "</a>"; | ||
}, | ||
link: function canRoute_link(name, options, props, merge) { | ||
return "<a " + formatAttributes( | ||
canReflect.assignMap({ | ||
href: canRoute_url(options, merge) | ||
}, props)) + ">" + name + "</a>"; | ||
}, | ||
isCurrent: function canRoute_isCurrent(options, subsetMatch) { | ||
if(subsetMatch) { | ||
// everything in options shouhld be in baseOptions | ||
var baseOptions = routeDeparam( bindingProxy.call("can.getValue") ); | ||
isCurrent: function canRoute_isCurrent(options, subsetMatch) { | ||
var getValueSymbol = bindingProxy.call("can.getValue"); | ||
if (subsetMatch) { | ||
// Everything in `options` shouhld be in `baseOptions`. | ||
var baseOptions = routeDeparam( getValueSymbol ); | ||
return matchCheck(options, baseOptions); | ||
} else { | ||
return bindingProxy.call("can.getValue") === routeParam(options); | ||
return getValueSymbol === routeParam(options); | ||
} | ||
} | ||
}; |
@@ -1,12 +0,12 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
QUnit.module("can-route .linkTo",{ | ||
setup: function(){ | ||
canRoute.routes = {}; | ||
} | ||
beforeEach: function(assert) { | ||
canRoute.routes = {}; | ||
} | ||
}); | ||
QUnit.test("linkTo", function () { | ||
QUnit.test("linkTo", function(assert) { | ||
canRoute.routes = {}; | ||
@@ -16,5 +16,5 @@ canRoute.register("{foo}"); | ||
foo: "bar", | ||
baz: 'foo' | ||
baz: "foo" | ||
}); | ||
equal(res, '<a href="#!bar&baz=foo">Hello</a>'); | ||
assert.equal(res, "<a href=\"#!bar&baz=foo\">Hello</a>"); | ||
}); |
@@ -9,7 +9,7 @@ var canRoute = require("can-route"); | ||
module.exports = { | ||
start: function(){ | ||
start: function() { | ||
// discard old hash | ||
this.hash = new RouteMock(); | ||
oldDefault = canRoute.urlData; | ||
canRoute.urlData = this.hash; | ||
canRoute.urlData = this.hash; | ||
@@ -20,5 +20,5 @@ this.hash.value = ""; | ||
}, | ||
stop: function(){ | ||
stop: function() { | ||
canRoute._teardown(); | ||
canRoute.urlData = oldDefault; | ||
canRoute.urlData = oldDefault; | ||
@@ -25,0 +25,0 @@ this.hash = new RouteMock(); |
@@ -1,3 +0,3 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
@@ -19,3 +19,3 @@ function getMsg(routes, input, method, output) { | ||
QUnit.module("can-route .param and .deparam",{ | ||
setup: function(){ | ||
beforeEach: function(assert) { | ||
canRoute.defaultBinding = "hashchange"; | ||
@@ -26,3 +26,3 @@ canRoute.routes = {}; | ||
test("param / deparam / rule", function () { | ||
QUnit.test("param / deparam / rule", function(assert) { | ||
var testCases = [ | ||
@@ -36,3 +36,3 @@ { | ||
input:"page=foo&bar=baz&where=there", | ||
output: { page: 'foo', bar: 'baz', where: 'there' } | ||
output: { page: "foo", bar: "baz", where: "there" } | ||
}, | ||
@@ -173,3 +173,3 @@ { | ||
routes: [ | ||
[ "pages/{page}/{section}/{subsection}", { page: 'default1', section: 'default2', subsection: 'default3' } ] | ||
[ "pages/{page}/{section}/{subsection}", { page: "default1", section: "default2", subsection: "default3" } ] | ||
], | ||
@@ -187,3 +187,3 @@ assertions: [ | ||
input: "pages/val1/val2/val3&invalid-parameters", | ||
output: { page: 'val1', section: 'val2', subsection: 'val3' } | ||
output: { page: "val1", section: "val2", subsection: "val3" } | ||
}, | ||
@@ -547,3 +547,3 @@ { | ||
if ("output" in assertion) { | ||
QUnit.deepEqual(actual, assertion.output, | ||
assert.deepEqual(actual, assertion.output, | ||
getMsg(testCase.routes, assertion.input, " --" + assertion.method + "-->", assertion.output) | ||
@@ -555,3 +555,3 @@ ); | ||
var reverseMethod = method.indexOf("de") === 0 ? method.slice(2) : "de" + method; | ||
QUnit.deepEqual(canRoute[reverseMethod].call(canRoute, actual), assertion.input, | ||
assert.deepEqual(canRoute[reverseMethod].call(canRoute, actual), assertion.input, | ||
getMsg(testCase.routes, assertion.input, " <---> ", actual) | ||
@@ -558,0 +558,0 @@ ); |
@@ -1,3 +0,3 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var SimpleMap = require("can-simple-map"); | ||
@@ -7,6 +7,6 @@ var canSymbol = require("can-symbol"); | ||
require('can-observation'); | ||
require("can-observation"); | ||
QUnit.module("can-route.data", { | ||
setup: function () { | ||
beforeEach: function(assert) { | ||
canRoute._teardown(); | ||
@@ -19,3 +19,3 @@ canRoute.defaultBinding = "hashchange"; | ||
test("can-route.data can be set to an element with a viewModel", function(){ | ||
QUnit.test("can-route.data can be set to an element with a viewModel", function(assert) { | ||
var element = document.createElement("div"); | ||
@@ -29,41 +29,43 @@ | ||
QUnit.equal(canRoute.data, vm, "works"); | ||
assert.equal(canRoute.data, vm, "works"); | ||
}); | ||
QUnit.asyncTest("Default map registers properties", function(){ | ||
mockRoute.start(); | ||
QUnit.test("Default map registers properties", function(assert) { | ||
var ready = assert.async(); | ||
mockRoute.start(); | ||
canRoute.register("{type}/{id}"); | ||
canRoute.register("{type}/{id}"); | ||
canRoute._onStartComplete = function () { | ||
canRoute._onStartComplete = function () { | ||
var after = mockRoute.hash.get(); | ||
equal(after, "cat/5", "same URL"); | ||
equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); | ||
equal(canRoute.data.id, "5", "conflicts should be won by the URL"); | ||
QUnit.start(); | ||
assert.equal(after, "cat/5", "same URL"); | ||
assert.equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); | ||
assert.equal(canRoute.data.id, "5", "conflicts should be won by the URL"); | ||
ready(); | ||
mockRoute.stop(); | ||
}; | ||
mockRoute.hash.value = "#!cat/5"; | ||
canRoute.start(); | ||
mockRoute.hash.value = "#!cat/5"; | ||
canRoute.start(); | ||
}); | ||
QUnit.asyncTest("Property defaults influence the Type", function(){ | ||
mockRoute.start(); | ||
QUnit.test("Property defaults influence the Type", function(assert) { | ||
var ready = assert.async(); | ||
mockRoute.start(); | ||
canRoute.register("{type}/{id}/{more}", { type: "dog", "id": 14, more: null }); | ||
canRoute.register("{type}/{id}/{more}", { type: "dog", "id": 14, more: null }); | ||
canRoute._onStartComplete = function () { | ||
canRoute._onStartComplete = function () { | ||
var after = mockRoute.hash.get(); | ||
equal(after, "cat/7/stuff", "same URL"); | ||
equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); | ||
deepEqual(canRoute.data.id, 7, "conflicts should be won by the URL"); | ||
deepEqual(canRoute.data.more, "stuff", "null defaults are converted"); | ||
QUnit.start(); | ||
assert.equal(after, "cat/7/stuff", "same URL"); | ||
assert.equal(canRoute.data.type, "cat", "conflicts should be won by the URL"); | ||
assert.deepEqual(canRoute.data.id, 7, "conflicts should be won by the URL"); | ||
assert.deepEqual(canRoute.data.more, "stuff", "null defaults are converted"); | ||
ready(); | ||
mockRoute.stop(); | ||
}; | ||
mockRoute.hash.value = "#!cat/7/stuff"; | ||
canRoute.start(); | ||
mockRoute.hash.value = "#!cat/7/stuff"; | ||
canRoute.start(); | ||
}); |
@@ -1,7 +0,7 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canReflect = require('can-reflect'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var canReflect = require("can-reflect"); | ||
QUnit.module("can-route with can-define/map/map in an iframe", { | ||
setup: function () { | ||
beforeEach: function() { | ||
canRoute._teardown(); | ||
@@ -19,7 +19,7 @@ canRoute.urlData = canRoute.bindings.hashchange; | ||
var teardownRouteTest; | ||
var setupRouteTest = function(callback){ | ||
var setupRouteTest = function(assert, callback){ | ||
var testarea = document.getElementById('qunit-fixture'); | ||
var iframe = document.createElement('iframe'); | ||
stop(); | ||
var testarea = document.getElementById("qunit-fixture"); | ||
var iframe = document.createElement("iframe"); | ||
var done = assert.async(); | ||
window.routeTestReady = function(){ | ||
@@ -36,3 +36,3 @@ var args = canReflect.toArray(arguments); | ||
setTimeout(function(){ | ||
start(); | ||
done(); | ||
},10); | ||
@@ -44,11 +44,11 @@ },1); | ||
if (typeof steal !== 'undefined') { | ||
test("listening to hashchange (#216, #124)", function () { | ||
if (typeof steal !== "undefined") { | ||
QUnit.test("listening to hashchange (#216, #124)", function(assert) { | ||
setupRouteTest(function (iframe, iCanRoute) { | ||
setupRouteTest(assert, function (iframe, iCanRoute) { | ||
ok(!iCanRoute.data.bla, 'Value not set yet'); | ||
assert.ok(!iCanRoute.data.bla, "Value not set yet"); | ||
iCanRoute.bind('bla', function(){ | ||
equal(iCanRoute.data.get("bla"), 'blu', 'Got route change event and value is as expected'); | ||
iCanRoute.bind("bla", function(){ | ||
assert.equal(iCanRoute.data.get("bla"), "blu", "Got route change event and value is as expected"); | ||
teardownRouteTest(); | ||
@@ -58,3 +58,3 @@ }); | ||
iCanRoute._onStartComplete = function () { | ||
iframe.src = iframe.src + '#!bla=blu'; | ||
iframe.src = iframe.src + "#!bla=blu"; | ||
}; | ||
@@ -66,7 +66,7 @@ | ||
test("updating the hash", function () { | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
QUnit.test("updating the hash", function(assert) { | ||
setupRouteTest(assert, function (iframe, iCanRoute, loc) { | ||
iCanRoute._onStartComplete = function () { | ||
var after = loc.href.substr(loc.href.indexOf("#")); | ||
equal(after, "#!bar/" + encodeURIComponent("\/")); | ||
assert.equal(after, "#!bar/" + encodeURIComponent("\/")); | ||
@@ -86,4 +86,4 @@ teardownRouteTest(); | ||
test("unsticky routes", function () { | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
QUnit.test("unsticky routes", function(assert) { | ||
setupRouteTest(assert, function (iframe, iCanRoute, loc) { | ||
@@ -101,3 +101,3 @@ iCanRoute.register("{type}"); | ||
var after = loc.href.substr(loc.href.indexOf("#")); | ||
equal(after, "#!bar"); | ||
assert.equal(after, "#!bar"); | ||
iCanRoute.attr({ | ||
@@ -115,3 +115,3 @@ type: "bar", | ||
if (isMatch || isWaitingTooLong) { | ||
equal(after, "#!bar/" + encodeURIComponent("\/"), "should go to type/id "+ (new Date() - time)); | ||
assert.equal(after, "#!bar/" + encodeURIComponent("\/"), "should go to type/id "+ (new Date() - time)); | ||
teardownRouteTest(); | ||
@@ -118,0 +118,0 @@ } else { |
/* jshint asi:true */ | ||
/* jshint -W079 */ | ||
require("./route-define-iframe-test"); | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var DefineMap = require('can-define/map/map'); | ||
var canReflect = require('can-reflect'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var DefineMap = require("can-define/map/map"); | ||
var canReflect = require("can-reflect"); | ||
var stacheKey = require("can-stache-key"); | ||
@@ -14,6 +14,6 @@ var Observation = require("can-observation"); | ||
require('can-observation'); | ||
require("can-observation"); | ||
QUnit.module("can/route with can-define/map/map", { | ||
setup: function () { | ||
beforeEach: function(assert) { | ||
canRoute.routes = {}; | ||
@@ -30,6 +30,6 @@ canRoute._teardown(); | ||
if (typeof steal !== 'undefined') { | ||
if (typeof steal !== "undefined") { | ||
QUnit.test("canRoute.map: conflicting route values, hash should win (canjs/canjs#979)", function(){ | ||
QUnit.stop(); | ||
QUnit.test("canRoute.map: conflicting route values, hash should win (canjs/canjs#979)", function(assert) { | ||
var done = assert.async(); | ||
mockRoute.start(); | ||
@@ -40,3 +40,3 @@ | ||
var AppState = DefineMap.extend({seal: false},{}); | ||
var appState = new AppState({type: "dog", id: '4'}); | ||
var appState = new AppState({type: "dog", id: "4"}); | ||
@@ -47,6 +47,6 @@ canRoute.data = appState; | ||
var after = mockRoute.hash.get(); | ||
equal(after, "cat/5", "same URL"); | ||
equal(appState.get("type"), "cat", "conflicts should be won by the URL"); | ||
equal(appState.get("id"), "5", "conflicts should be won by the URL"); | ||
QUnit.start(); | ||
assert.equal(after, "cat/5", "same URL"); | ||
assert.equal(appState.get("type"), "cat", "conflicts should be won by the URL"); | ||
assert.equal(appState.get("id"), "5", "conflicts should be won by the URL"); | ||
done(); | ||
mockRoute.stop(); | ||
@@ -59,4 +59,4 @@ }; | ||
QUnit.test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data (canjs/canjs#979)", function(){ | ||
QUnit.stop(); | ||
QUnit.test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data (canjs/canjs#979)", function(assert) { | ||
var done = assert.async(); | ||
mockRoute.start(); | ||
@@ -66,3 +66,3 @@ | ||
var AppState = DefineMap.extend({seal: false},{}); | ||
var appState = new AppState({section: 'home'}); | ||
var appState = new AppState({section: "home"}); | ||
@@ -72,10 +72,10 @@ canRoute.data = appState; | ||
canRoute._onStartComplete = function () { | ||
equal(mockRoute.hash.value, "cat/5§ion=home", "same URL"); | ||
equal(appState.get("type"), "cat", "hash populates the appState"); | ||
equal(appState.get("id"), "5", "hash populates the appState"); | ||
equal(appState.get("section"), "home", "appState keeps its properties"); | ||
ok(canRoute.data === appState, "canRoute.data is the same as appState"); | ||
assert.equal(mockRoute.hash.value, "cat/5§ion=home", "same URL"); | ||
assert.equal(appState.get("type"), "cat", "hash populates the appState"); | ||
assert.equal(appState.get("id"), "5", "hash populates the appState"); | ||
assert.equal(appState.get("section"), "home", "appState keeps its properties"); | ||
assert.ok(canRoute.data === appState, "canRoute.data is the same as appState"); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
done(); | ||
}; | ||
@@ -87,5 +87,5 @@ | ||
test("sticky enough routes (canjs#36)", function () { | ||
QUnit.test("sticky enough routes (canjs#36)", function(assert) { | ||
QUnit.stop(); | ||
var done = assert.async(); | ||
@@ -102,5 +102,5 @@ mockRoute.start(); | ||
var after = mockRoute.hash.get(); | ||
equal(after, "active"); | ||
assert.equal(after, "active"); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
done(); | ||
@@ -110,45 +110,48 @@ }, 30); | ||
QUnit.asyncTest("canRoute.current is live-bindable (#1156)", function () { | ||
mockRoute.start(); | ||
QUnit.test("canRoute.current is live-bindable (#1156)", function(assert) { | ||
var ready = assert.async(); | ||
mockRoute.start(); | ||
canRoute.start(); | ||
var isOnTestPage = new Observation(function isCurrent(){ | ||
canRoute.start(); | ||
var isOnTestPage = new Observation(function isCurrent(){ | ||
return canRoute.isCurrent({page: "test"}); | ||
}); | ||
canReflect.onValue(isOnTestPage, function isCurrentChanged(){ | ||
canReflect.onValue(isOnTestPage, function isCurrentChanged(){ | ||
// unbind now because isCurrent depends on urlData | ||
isOnTestPage.off(); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
ready(); | ||
}); | ||
equal(canRoute.isCurrent({page: "test"}), false, "initially not on test page") | ||
setTimeout(function(){ | ||
assert.equal(canRoute.isCurrent({page: "test"}), false, "initially not on test page") | ||
setTimeout(function(){ | ||
canRoute.data.set("page","test"); | ||
},20); | ||
}); | ||
}); | ||
QUnit.asyncTest("can.compute.read should not call canRoute (#1154)", function () { | ||
mockRoute.start(); | ||
canRoute.attr("page","test"); | ||
canRoute.start(); | ||
QUnit.test("can.compute.read should not call canRoute (#1154)", function(assert) { | ||
var ready = assert.async(); | ||
mockRoute.start(); | ||
canRoute.attr("page","test"); | ||
canRoute.start(); | ||
var val = stacheKey.read({route: canRoute},stacheKey.reads("route")).value; | ||
var val = stacheKey.read({route: canRoute},stacheKey.reads("route")).value; | ||
setTimeout(function(){ | ||
equal(val,canRoute,"read correctly"); | ||
setTimeout(function(){ | ||
assert.equal(val,canRoute,"read correctly"); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
ready(); | ||
},1); | ||
}); | ||
}); | ||
QUnit.asyncTest("routes should deep clean", function() { | ||
expect(2); | ||
QUnit.test("routes should deep clean", function(assert) { | ||
var ready = assert.async(); | ||
assert.expect(2); | ||
mockRoute.start(); | ||
mockRoute.start(); | ||
var hash1 = canRoute.url({ | ||
var hash1 = canRoute.url({ | ||
panelA: { | ||
@@ -160,3 +163,3 @@ name: "fruit", | ||
}); | ||
var hash2 = canRoute.url({ | ||
var hash2 = canRoute.url({ | ||
panelA: { | ||
@@ -168,31 +171,32 @@ name: "fruit", | ||
}); | ||
mockRoute.hash.value = hash1; | ||
mockRoute.hash.value = hash2; | ||
mockRoute.hash.value = hash1; | ||
mockRoute.hash.value = hash2; | ||
canRoute._onStartComplete = function() { | ||
equal(canRoute.data.get('panelA').id, 20, "id should change"); | ||
equal(canRoute.data.get('panelA').show, undefined, "show should be removed"); | ||
canRoute._onStartComplete = function() { | ||
assert.equal(canRoute.data.get("panelA").id, 20, "id should change"); | ||
assert.equal(canRoute.data.get("panelA").show, undefined, "show should be removed"); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
ready(); | ||
}; | ||
canRoute.start(); | ||
}); | ||
canRoute.start(); | ||
}); | ||
QUnit.asyncTest("updating bound DefineMap causes single update with a coerced string value", function() { | ||
expect(1); | ||
QUnit.test("updating bound DefineMap causes single update with a coerced string value", function(assert) { | ||
var ready = assert.async(); | ||
assert.expect(1); | ||
canRoute.start(); | ||
var MyMap = DefineMap.extend({seal: false},{'*': "stringOrObservable"}); | ||
var appVM = new MyMap(); | ||
canRoute.start(); | ||
var MyMap = DefineMap.extend({seal: false},{"*": "stringOrObservable"}); | ||
var appVM = new MyMap(); | ||
canRoute.data = appVM; | ||
canRoute.data = appVM; | ||
canRoute._onStartComplete = function(){ | ||
appVM.on('action', function(ev, newVal) { | ||
strictEqual(newVal, '10'); | ||
canRoute._onStartComplete = function(){ | ||
appVM.on("action", function(ev, newVal) { | ||
assert.strictEqual(newVal, "10"); | ||
}); | ||
appVM.set('action', 10); | ||
appVM.set("action", 10); | ||
@@ -202,10 +206,10 @@ // check after 30ms to see that we only have a single call | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
ready(); | ||
}, 5); | ||
}; | ||
canRoute.start(); | ||
}); | ||
canRoute.start(); | ||
}); | ||
test("hash doesn't update to itself with a !", function() { | ||
stop(); | ||
QUnit.test("hash doesn't update to itself with a !", function(assert) { | ||
var done = assert.async(); | ||
window.routeTestReady = function (iCanRoute, loc) { | ||
@@ -216,9 +220,9 @@ | ||
iCanRoute.attr('path', 'foo'); | ||
iCanRoute.attr("path", "foo"); | ||
setTimeout(function() { | ||
var counter = 0; | ||
try { | ||
equal(loc.hash, '#!foo'); | ||
assert.equal(loc.hash, "#!foo"); | ||
} catch(e) { | ||
start(); | ||
done(); | ||
throw e; | ||
@@ -234,6 +238,6 @@ } | ||
try { | ||
equal(loc.hash, '#bar'); | ||
equal(counter, 1); //sanity check -- bindings only ran once before this change. | ||
assert.equal(loc.hash, "#bar"); | ||
assert.equal(counter, 1); //sanity check -- bindings only ran once before this change. | ||
} finally { | ||
start(); | ||
done(); | ||
} | ||
@@ -243,3 +247,3 @@ }, 100); | ||
}; | ||
var iframe = document.createElement('iframe'); | ||
var iframe = document.createElement("iframe"); | ||
iframe.src = __dirname+"/define-testing.html?1"; | ||
@@ -252,3 +256,3 @@ this.fixture.appendChild(iframe); | ||
test("escaping periods", function () { | ||
QUnit.test("escaping periods", function(assert) { | ||
@@ -261,7 +265,7 @@ canRoute.routes = {}; | ||
var obj = canRoute.deparam("can.Control.html"); | ||
deepEqual(obj, { | ||
assert.deepEqual(obj, { | ||
page: "can.Control" | ||
}); | ||
equal(canRoute.param({ | ||
assert.equal(canRoute.param({ | ||
page: "can.Control" | ||
@@ -272,5 +276,5 @@ }), "can.Control.html"); | ||
if (typeof require !== 'undefined') { | ||
if (typeof require !== "undefined") { | ||
test("correct stringing", function () { | ||
QUnit.test("correct stringing", function(assert) { | ||
mockRoute.start(); | ||
@@ -287,3 +291,3 @@ | ||
QUnit.deepEqual(canRoute.attr(),{ | ||
assert.deepEqual(canRoute.attr(),{ | ||
number: "1", | ||
@@ -307,3 +311,3 @@ bool: "true", | ||
QUnit.deepEqual(canRoute.attr(), { | ||
assert.deepEqual(canRoute.attr(), { | ||
number: "1", | ||
@@ -325,3 +329,3 @@ bool: "true", | ||
canRoute.attr({ | ||
type: 'page', | ||
type: "page", | ||
id: 10, | ||
@@ -331,3 +335,3 @@ sort_by_name: true | ||
propEqual(canRoute.attr(), { | ||
assert.propEqual(canRoute.attr(), { | ||
type: "page", | ||
@@ -342,20 +346,20 @@ id: "10", | ||
test("on/off binding", function () { | ||
QUnit.test("on/off binding", function(assert) { | ||
canRoute.routes = {}; | ||
expect(1) | ||
assert.expect(1) | ||
canRoute.on('foo', function () { | ||
ok(true, "foo called"); | ||
canRoute.on("foo", function () { | ||
assert.ok(true, "foo called"); | ||
canRoute.off('foo'); | ||
canRoute.off("foo"); | ||
canRoute.attr('foo', 'baz'); | ||
canRoute.attr("foo", "baz"); | ||
}); | ||
canRoute.attr('foo', 'bar'); | ||
canRoute.attr("foo", "bar"); | ||
}); | ||
test("two way binding canRoute.map with DefineMap instance", function(){ | ||
expect(2); | ||
stop(); | ||
QUnit.test("two way binding canRoute.map with DefineMap instance", function(assert) { | ||
assert.expect(2); | ||
var done = assert.async(); | ||
mockRoute.start(); | ||
@@ -371,19 +375,19 @@ | ||
canRoute.serializedCompute.bind('change', function(){ | ||
canRoute.serializedCompute.bind("change", function(){ | ||
equal(canRoute.attr('name'), 'Brian', 'appState is bound to canRoute'); | ||
canRoute.serializedCompute.unbind('change'); | ||
assert.equal(canRoute.attr("name"), "Brian", "appState is bound to canRoute"); | ||
canRoute.serializedCompute.unbind("change"); | ||
appState.name = undefined; | ||
setTimeout(function(){ | ||
equal( mockRoute.hash.get(), ""); | ||
assert.equal( mockRoute.hash.get(), ""); | ||
mockRoute.stop(); | ||
start(); | ||
done(); | ||
},20); | ||
}); | ||
appState.set('name', 'Brian'); | ||
appState.set("name", "Brian"); | ||
}); | ||
test(".url with merge=true", function(){ | ||
QUnit.test(".url with merge=true", function(assert) { | ||
mockRoute.start() | ||
@@ -398,5 +402,5 @@ | ||
QUnit.stop(); | ||
var done = assert.async(); | ||
appState.set('foo', 'bar'); | ||
appState.set("foo", "bar"); | ||
@@ -406,6 +410,6 @@ // TODO: expose a way to know when the url has changed. | ||
var result = canRoute.url({page: "recipe", id: 5}, true); | ||
QUnit.equal(result, "#!&foo=bar&page=recipe&id=5"); | ||
assert.equal(result, "#!&foo=bar&page=recipe&id=5"); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
done(); | ||
},20); | ||
@@ -421,3 +425,3 @@ | ||
test("param with whitespace in interpolated string (#45)", function () { | ||
QUnit.test("param with whitespace in interpolated string (#45)", function(assert) { | ||
canRoute.routes = {}; | ||
@@ -431,3 +435,3 @@ canRoute.register("{ page }", { | ||
}); | ||
equal(res, "") | ||
assert.equal(res, "") | ||
@@ -445,3 +449,3 @@ canRoute.register("pages/{ p1 }/{ p2 }/{ p3 }", { | ||
}); | ||
equal(res, "pages///") | ||
assert.equal(res, "pages///") | ||
@@ -453,7 +457,7 @@ res = canRoute.param({ | ||
}); | ||
equal(res, "pages//baz/") | ||
assert.equal(res, "pages//baz/") | ||
}); | ||
test("triggers __url event anytime a there's a change to individual properties", function(){ | ||
QUnit.test("triggers __url event anytime a there's a change to individual properties", function(assert) { | ||
mockRoute.start(); | ||
@@ -465,6 +469,6 @@ | ||
canRoute.data = appState; | ||
canRoute.register('{page}'); | ||
canRoute.register('{page}/{section}'); | ||
canRoute.register("{page}"); | ||
canRoute.register("{page}/{section}"); | ||
QUnit.stop(); | ||
var done = assert.async(); | ||
canRoute.start(); | ||
@@ -475,16 +479,16 @@ | ||
1: function section_a() { | ||
canRoute.data.section = 'a'; | ||
canRoute.data.section = "a"; | ||
}, | ||
2: function section_b() { | ||
canRoute.data.section = 'b'; | ||
canRoute.data.section = "b"; | ||
}, | ||
3: function(){ | ||
// 1st call is going from undefined to empty string | ||
equal(matchedCount, 3, 'calls __url event every time a property is changed'); | ||
assert.equal(matchedCount, 3, "calls __url event every time a property is changed"); | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
done(); | ||
} | ||
} | ||
canRoute.on('__url', function updateMatchedCount() { | ||
canRoute.on("__url", function updateMatchedCount() { | ||
// any time a route property is changed, not just the matched route | ||
@@ -496,3 +500,3 @@ matchedCount++; | ||
setTimeout(function page_two() { | ||
canRoute.data.page = 'two'; | ||
canRoute.data.page = "two"; | ||
}, 50); | ||
@@ -503,25 +507,26 @@ | ||
QUnit.asyncTest("updating unserialized prop on bound DefineMap causes single update without a coerced string value", function() { | ||
expect(1); | ||
canRoute.routes = {}; | ||
mockRoute.start(); | ||
QUnit.test("updating unserialized prop on bound DefineMap causes single update without a coerced string value", function(assert) { | ||
var ready = assert.async(); | ||
assert.expect(1); | ||
canRoute.routes = {}; | ||
mockRoute.start(); | ||
var appVM = new (DefineMap.extend({ | ||
var appVM = new (DefineMap.extend({ | ||
action: {serialize: false, type: "*"} | ||
}))(); | ||
canRoute.data = appVM; | ||
canRoute.start(); | ||
canRoute.data = appVM; | ||
canRoute.start(); | ||
appVM.bind('action', function(ev, newVal) { | ||
equal(typeof newVal, 'function'); | ||
appVM.bind("action", function(ev, newVal) { | ||
assert.equal(typeof newVal, "function"); | ||
}); | ||
appVM.set('action', function() {}); | ||
appVM.set("action", function() {}); | ||
// check after 30ms to see that we only have a single call | ||
setTimeout(function() { | ||
// check after 30ms to see that we only have a single call | ||
setTimeout(function() { | ||
mockRoute.stop(); | ||
QUnit.start(); | ||
ready(); | ||
}, 5); | ||
}); |
/* jshint asi:true */ | ||
/* jshint -W079 */ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canReflect = require('can-reflect'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var canReflect = require("can-reflect"); | ||
QUnit.module("can/route with can-map", { | ||
setup: function () { | ||
beforeEach: function(assert) { | ||
canRoute._teardown(); | ||
@@ -19,7 +19,7 @@ canRoute.defaultBinding = "hashchange"; | ||
var teardownRouteTest; | ||
var setupRouteTest = function(callback){ | ||
var setupRouteTest = function(assert, callback){ | ||
var testarea = document.getElementById('qunit-fixture'); | ||
var iframe = document.createElement('iframe'); | ||
stop(); | ||
var testarea = document.getElementById("qunit-fixture"); | ||
var iframe = document.createElement("iframe"); | ||
var done = assert.async(); | ||
window.routeTestReady = function(iCanRoute){ | ||
@@ -36,3 +36,3 @@ var args = canReflect.toArray(arguments) | ||
setTimeout(function(){ | ||
start(); | ||
done(); | ||
},10); | ||
@@ -44,11 +44,11 @@ },1); | ||
if (typeof steal !== 'undefined') { | ||
test("listening to hashchange (#216, #124)", function () { | ||
if (typeof steal !== "undefined") { | ||
QUnit.test("listening to hashchange (#216, #124)", function(assert) { | ||
setupRouteTest(function (iframe, iCanRoute) { | ||
setupRouteTest(assert, function (iframe, iCanRoute) { | ||
ok(!iCanRoute.attr('bla'), 'Value not set yet'); | ||
assert.ok(!iCanRoute.attr("bla"), "Value not set yet"); | ||
iCanRoute.bind('change', function () { | ||
equal(iCanRoute.attr('bla'), 'blu', 'Got route change event and value is as expected'); | ||
iCanRoute.bind("change", function () { | ||
assert.equal(iCanRoute.attr("bla"), "blu", "Got route change event and value is as expected"); | ||
teardownRouteTest(); | ||
@@ -58,3 +58,3 @@ }); | ||
iCanRoute._onStartComplete = function () { | ||
iframe.src = iframe.src + '#!bla=blu'; | ||
iframe.src = iframe.src + "#!bla=blu"; | ||
}; | ||
@@ -68,5 +68,5 @@ | ||
test("removing things from the hash", function () { | ||
QUnit.test("removing things from the hash", function(assert) { | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
setupRouteTest(assert, function (iframe, iCanRoute, loc) { | ||
// CanJS's build was failing on this test. | ||
@@ -78,3 +78,3 @@ // This code is to make sure we can more information on why the build | ||
if(outerChangeCalled === false) { | ||
QUnit.ok(outerChangeCalled, "no outer change called"); | ||
assert.ok(outerChangeCalled, "no outer change called"); | ||
teardownRouteTest(); | ||
@@ -84,6 +84,6 @@ } | ||
iCanRoute.bind('change', function change1() { | ||
iCanRoute.bind("change", function change1() { | ||
outerChangeCalled = true; | ||
equal(iCanRoute.attr('foo'), 'bar', 'expected value'); | ||
iCanRoute.unbind('change'); | ||
assert.equal(iCanRoute.attr("foo"), "bar", "expected value"); | ||
iCanRoute.unbind("change"); | ||
@@ -93,13 +93,13 @@ var changeFired = false, | ||
iCanRoute.bind('change', function change2(ev, prop){ | ||
iCanRoute.bind("change", function change2(ev, prop){ | ||
changeFired = true; | ||
equal(iCanRoute.attr('personId'), '3', 'personId'); | ||
equal(iCanRoute.attr('foo'), undefined, 'unexpected value'); | ||
iCanRoute.unbind('change'); | ||
assert.equal(iCanRoute.attr("personId"), "3", "personId"); | ||
assert.equal(iCanRoute.attr("foo"), undefined, "unexpected value"); | ||
iCanRoute.unbind("change"); | ||
if (prop === 'personId') { | ||
if (prop === "personId") { | ||
tearDown = true; | ||
teardownRouteTest(); | ||
} else { | ||
QUnit.equal(prop, "foo", "removed foo"); | ||
assert.equal(prop, "foo", "removed foo"); | ||
} | ||
@@ -113,4 +113,4 @@ }); | ||
if(tearDown === false) { | ||
QUnit.ok(changeFired, "changed was fired"); | ||
QUnit.ok(false, "no personId change"); | ||
assert.ok(changeFired, "changed was fired"); | ||
assert.ok(false, "no personId change"); | ||
teardownRouteTest(); | ||
@@ -122,3 +122,3 @@ } | ||
setTimeout(function () { | ||
iframe.contentWindow.location.hash = '#!personId=3'; | ||
iframe.contentWindow.location.hash = "#!personId=3"; | ||
}, 150); | ||
@@ -130,3 +130,3 @@ | ||
iCanRoute._onStartComplete = function () { | ||
iframe.contentWindow.location.hash = '#!foo=bar'; | ||
iframe.contentWindow.location.hash = "#!foo=bar"; | ||
}; | ||
@@ -138,8 +138,8 @@ | ||
test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data", function(){ | ||
setupRouteTest(function (iframe, iCanRoute, loc, win) { | ||
QUnit.test("canRoute.map: route is initialized from URL first, then URL params are added from canRoute.data", function(assert) { | ||
setupRouteTest(assert, function (iframe, iCanRoute, loc, win) { | ||
iCanRoute.register("{type}/{id}"); | ||
var AppState = win.CanMap.extend(); | ||
var appState = new AppState({section: 'home'}); | ||
var appState = new AppState({section: "home"}); | ||
@@ -150,7 +150,7 @@ iCanRoute.data = appState; | ||
var after = loc.href.substr(loc.href.indexOf("#")); | ||
equal(after, "#!cat/5§ion=home", "same URL"); | ||
equal(appState.attr("type"), "cat", "hash populates the appState"); | ||
equal(appState.attr("id"), "5", "hash populates the appState"); | ||
equal(appState.attr("section"), "home", "appState keeps its properties"); | ||
ok(iCanRoute.data === appState, "canRoute.data is the same as appState"); | ||
assert.equal(after, "#!cat/5§ion=home", "same URL"); | ||
assert.equal(appState.attr("type"), "cat", "hash populates the appState"); | ||
assert.equal(appState.attr("id"), "5", "hash populates the appState"); | ||
assert.equal(appState.attr("section"), "home", "appState keeps its properties"); | ||
assert.ok(iCanRoute.data === appState, "canRoute.data is the same as appState"); | ||
@@ -166,7 +166,7 @@ | ||
test("updating the hash", function () { | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
QUnit.test("updating the hash", function(assert) { | ||
setupRouteTest(assert, function (iframe, iCanRoute, loc) { | ||
iCanRoute._onStartComplete = function () { | ||
var after = loc.href.substr(loc.href.indexOf("#")); | ||
equal(after, "#!bar/" + encodeURIComponent("\/")); | ||
assert.equal(after, "#!bar/" + encodeURIComponent("\/")); | ||
@@ -185,5 +185,5 @@ teardownRouteTest(); | ||
test("sticky enough routes", function () { | ||
QUnit.test("sticky enough routes", function(assert) { | ||
setupRouteTest(function (iframe, iCanRoute, loc) { | ||
setupRouteTest(assert, function (iframe, iCanRoute, loc) { | ||
@@ -199,3 +199,3 @@ iCanRoute.start() | ||
var after = loc.href.substr(loc.href.indexOf("#")); | ||
equal(after, "#!active"); | ||
assert.equal(after, "#!active"); | ||
@@ -208,6 +208,6 @@ teardownRouteTest(); | ||
test("updating bound SimpleMap causes single update with a coerced string value", function() { | ||
expect(1); | ||
QUnit.test("updating bound SimpleMap causes single update with a coerced string value", function(assert) { | ||
assert.expect(1); | ||
setupRouteTest(function (iframe, route, loc, win) { | ||
setupRouteTest(assert, function (iframe, route, loc, win) { | ||
var appVM = new win.CanMap(); | ||
@@ -218,7 +218,7 @@ | ||
appVM.bind('action', function(ev, newVal) { | ||
strictEqual(newVal, '10'); | ||
appVM.bind("action", function(ev, newVal) { | ||
assert.strictEqual(newVal, "10"); | ||
}); | ||
appVM.attr('action', 10); | ||
appVM.attr("action", 10); | ||
@@ -232,4 +232,4 @@ // check after 30ms to see that we only have a single call | ||
test("hash doesn't update to itself with a !", function() { | ||
stop(); | ||
QUnit.test("hash doesn't update to itself with a !", function(assert) { | ||
var done = assert.async(); | ||
window.routeTestReady = function (iCanRoute, loc) { | ||
@@ -240,9 +240,9 @@ | ||
iCanRoute.attr('path', 'foo'); | ||
iCanRoute.attr("path", "foo"); | ||
setTimeout(function() { | ||
var counter = 0; | ||
try { | ||
equal(loc.hash, '#!foo'); | ||
assert.equal(loc.hash, "#!foo"); | ||
} catch(e) { | ||
start(); | ||
done(); | ||
throw e; | ||
@@ -258,6 +258,6 @@ } | ||
try { | ||
equal(loc.hash, '#bar'); | ||
equal(counter, 1); //sanity check -- bindings only ran once before this change. | ||
assert.equal(loc.hash, "#bar"); | ||
assert.equal(counter, 1); //sanity check -- bindings only ran once before this change. | ||
} finally { | ||
start(); | ||
done(); | ||
} | ||
@@ -267,3 +267,3 @@ }, 100); | ||
}; | ||
var iframe = document.createElement('iframe'); | ||
var iframe = document.createElement("iframe"); | ||
iframe.src = __dirname+"/testing.html?1"; | ||
@@ -276,3 +276,3 @@ this.fixture.appendChild(iframe); | ||
test("escaping periods", function () { | ||
QUnit.test("escaping periods", function(assert) { | ||
@@ -285,7 +285,7 @@ canRoute.routes = {}; | ||
var obj = canRoute.deparam("can.Control.html"); | ||
deepEqual(obj, { | ||
assert.deepEqual(obj, { | ||
page: "can.Control" | ||
}); | ||
equal(canRoute.param({ | ||
assert.equal(canRoute.param({ | ||
page: "can.Control" | ||
@@ -296,11 +296,11 @@ }), "can.Control.html"); | ||
if (typeof require === 'undefined') { | ||
if (typeof require === "undefined") { | ||
test("correct stringing", function () { | ||
setupRouteTest(function(iframe, route) { | ||
QUnit.test("correct stringing", function(assert) { | ||
setupRouteTest(assert, function(iframe, route) { | ||
route.routes = {}; | ||
route.attr('number', 1); | ||
propEqual(route.attr(), { | ||
'number': "1" | ||
route.attr("number", 1); | ||
assert.propEqual(route.attr(), { | ||
"number": "1" | ||
}); | ||
@@ -312,4 +312,4 @@ | ||
propEqual(route.attr(), { | ||
'bool': "true" | ||
assert.propEqual(route.attr(), { | ||
"bool": "true" | ||
}); | ||
@@ -320,4 +320,4 @@ | ||
}, true); | ||
propEqual(route.attr(), { | ||
'string': "hello" | ||
assert.propEqual(route.attr(), { | ||
"string": "hello" | ||
}); | ||
@@ -328,4 +328,4 @@ | ||
}, true); | ||
propEqual(route.attr(), { | ||
'array': ["1", "true", "hello"] | ||
assert.propEqual(route.attr(), { | ||
"array": ["1", "true", "hello"] | ||
}); | ||
@@ -344,3 +344,3 @@ | ||
propEqual(route.attr(), { | ||
assert.propEqual(route.attr(), { | ||
number: "1", | ||
@@ -360,3 +360,3 @@ bool: "true", | ||
route.attr({ | ||
type: 'page', | ||
type: "page", | ||
id: 10, | ||
@@ -366,3 +366,3 @@ sort_by_name: true | ||
propEqual(route.attr(), { | ||
assert.propEqual(route.attr(), { | ||
type: "page", | ||
@@ -379,9 +379,9 @@ id: "10", | ||
test("Calling attr with an object should not stringify object (#197)", function () { | ||
setupRouteTest(function (iframe, iCanRoute, loc, win) { | ||
QUnit.test("Calling attr with an object should not stringify object (#197)", function(assert) { | ||
setupRouteTest(assert, function (iframe, iCanRoute, loc, win) { | ||
var app = new win.CanMap({}); | ||
app.define = { foo: { serialize: false } }; | ||
app.attr('foo', true); | ||
equal(app.attr('foo'), true, 'not route data - .attr("foo", ...) works'); | ||
app.attr("foo", true); | ||
assert.equal(app.attr("foo"), true, "not route data - .attr(\"foo\", ...) works"); | ||
@@ -391,8 +391,8 @@ app.attr({ | ||
}); | ||
equal(app.attr('foo'), false, 'not route data - .attr({"foo": ...}) works'); | ||
assert.equal(app.attr("foo"), false, "not route data - .attr({\"foo\": ...}) works"); | ||
iCanRoute.data = app; | ||
app.attr('foo', true); | ||
equal(app.attr('foo'), true, 'route data - .attr("foo", ...) works'); | ||
app.attr("foo", true); | ||
assert.equal(app.attr("foo"), true, "route data - .attr(\"foo\", ...) works"); | ||
@@ -402,3 +402,3 @@ app.attr({ | ||
}); | ||
equal(app.attr('foo'), false, 'route data - .attr({"foo": ...}) works'); | ||
assert.equal(app.attr("foo"), false, "route data - .attr({\"foo\": ...}) works"); | ||
@@ -405,0 +405,0 @@ teardownRouteTest(); |
@@ -1,3 +0,3 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var mockRoute = require("./mock-route-binding"); | ||
@@ -7,19 +7,19 @@ var DefineMap = require("can-define/map/"); | ||
QUnit.module("can-route observablility",{ | ||
setup: function(){ | ||
canRoute.routes = {}; | ||
} | ||
beforeEach: function(assert) { | ||
canRoute.routes = {}; | ||
} | ||
}); | ||
QUnit.test("on/off binding", function () { | ||
QUnit.test("on/off binding", function(assert) { | ||
canRoute.routes = {}; | ||
expect(1); | ||
canRoute.on('foo', function () { | ||
ok(true, "foo called"); | ||
assert.expect(1); | ||
canRoute.on("foo", function () { | ||
assert.ok(true, "foo called"); | ||
canRoute.off('foo'); | ||
canRoute.off("foo"); | ||
canRoute.attr('foo', 'baz'); | ||
canRoute.attr("foo", "baz"); | ||
}); | ||
canRoute.attr('foo', 'bar'); | ||
canRoute.attr("foo", "bar"); | ||
}); | ||
@@ -29,6 +29,6 @@ | ||
//queues.log("flush"); | ||
test("currentRule() compute", function() { | ||
QUnit.test("currentRule() compute", function(assert) { | ||
mockRoute.start(); | ||
QUnit.stop(); | ||
var done = assert.async(); | ||
@@ -48,10 +48,10 @@ var AppState = DefineMap.extend({ | ||
equal(appState.route, undefined, "should not set route on appState"); | ||
equal(canRoute.currentRule(), "{type}", "should set route.currentRule property"); | ||
assert.equal(appState.route, undefined, "should not set route on appState"); | ||
assert.equal(canRoute.currentRule(), "{type}", "should set route.currentRule property"); | ||
appState.subtype = "bar"; | ||
var check = function(){ | ||
if(canRoute.currentRule() === "{type}/{subtype}") { | ||
QUnit.ok(true, "moved to right route"); | ||
assert.ok(true, "moved to right route"); | ||
mockRoute.stop(); | ||
start(); | ||
done(); | ||
} else { | ||
@@ -58,0 +58,0 @@ setTimeout(check, 20); |
@@ -1,3 +0,3 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var observe = require("can-observe"); | ||
@@ -8,11 +8,11 @@ var mockRoute = require("./mock-route-binding"); | ||
QUnit.module("can-route observe",{ | ||
setup: function(){ | ||
canRoute.routes = {}; | ||
} | ||
beforeEach: function(assert) { | ||
canRoute.routes = {}; | ||
} | ||
}); | ||
QUnit.test("two way binding canRoute.map with a can-observe instance", function(){ | ||
QUnit.test("two way binding canRoute.map with a can-observe instance", function(assert) { | ||
expect(3); | ||
stop(); | ||
assert.expect(3); | ||
var done = assert.async(); | ||
mockRoute.start(); | ||
@@ -26,18 +26,18 @@ | ||
canReflect.onValue( mockRoute.hash, function handler1(newVal){ | ||
QUnit.equal(newVal, "#&name=Brian", "updated hash"); | ||
canReflect.offValue( mockRoute.hash, handler1); | ||
QUnit.equal(canRoute.data.name, 'Brian', 'appState is bound to canRoute'); | ||
canReflect.onValue( mockRoute.hash, function handler1(newVal){ | ||
assert.equal(newVal, "#&name=Brian", "updated hash"); | ||
canReflect.offValue( mockRoute.hash, handler1); | ||
assert.equal(canRoute.data.name, "Brian", "appState is bound to canRoute"); | ||
canReflect.onValue( mockRoute.hash, function handler2(newVal){ | ||
equal( newVal, "#"); | ||
mockRoute.stop(); | ||
start(); | ||
}); | ||
canReflect.onValue( mockRoute.hash, function handler2(newVal){ | ||
assert.equal( newVal, "#"); | ||
mockRoute.stop(); | ||
done(); | ||
}); | ||
delete appState.name; | ||
delete appState.name; | ||
}); | ||
}); | ||
appState.name = "Brian"; | ||
}); |
@@ -1,7 +0,7 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var testHelpers = require('can-test-helpers'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var testHelpers = require("can-test-helpers"); | ||
QUnit.module("can-route .register", { | ||
setup: function(){ | ||
beforeEach: function(assert) { | ||
canRoute.routes = {}; | ||
@@ -11,3 +11,3 @@ } | ||
testHelpers.dev.devOnlyTest("should warn when two routes have same map properties", function () { | ||
testHelpers.dev.devOnlyTest("should warn when two routes have same map properties", function (assert) { | ||
var teardown = testHelpers.dev.willWarn(/two routes were registered with matching keys/); | ||
@@ -18,6 +18,6 @@ | ||
equal(teardown(), 1); | ||
assert.equal(teardown(), 1); | ||
}); | ||
testHelpers.dev.devOnlyTest("should warn when two routes have same map properties - including defaults", function () { | ||
testHelpers.dev.devOnlyTest("should warn when two routes have same map properties - including defaults", function (assert) { | ||
var teardown = testHelpers.dev.willWarn(/two routes were registered with matching keys/); | ||
@@ -28,6 +28,6 @@ | ||
equal(teardown(), 1); | ||
assert.equal(teardown(), 1); | ||
}); | ||
testHelpers.dev.devOnlyTest("should not warn when two routes have same map properties - but different defaults(#36)", function () { | ||
testHelpers.dev.devOnlyTest("should not warn when two routes have same map properties - but different defaults(#36)", function (assert) { | ||
var teardown = testHelpers.dev.willWarn(/two routes were registered with matching keys/); | ||
@@ -38,10 +38,10 @@ | ||
equal(teardown(), 0); | ||
assert.equal(teardown(), 0); | ||
}); | ||
testHelpers.dev.devOnlyTest("should not be display warning for matching keys when the routes do not match (#99)", function () { | ||
var expectedWarningText = 'two routes were registered with matching keys:\n' + | ||
'\t(1) route.register("login", {"page":"auth"})\n' + | ||
'\t(2) route.register("signup", {"page":"auth"})\n' + | ||
'(1) will always be chosen since it was registered first'; | ||
testHelpers.dev.devOnlyTest("should not be display warning for matching keys when the routes do not match (#99)", function (assert) { | ||
var expectedWarningText = "two routes were registered with matching keys:\n" + | ||
"\t(1) route.register(\"login\", {\"page\":\"auth\"})\n" + | ||
"\t(2) route.register(\"signup\", {\"page\":\"auth\"})\n" + | ||
"(1) will always be chosen since it was registered first"; | ||
@@ -62,3 +62,3 @@ var teardown = testHelpers.dev.willWarn(expectedWarningText); | ||
equal(teardown(), 1); | ||
assert.equal(teardown(), 1); | ||
}); |
@@ -1,10 +0,10 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var SimpleMap = require("can-simple-map"); | ||
var mock = require("./mock-route-binding"); | ||
require('can-observation'); | ||
require("can-observation"); | ||
QUnit.module("can-route.stop", { | ||
setup: function () { | ||
beforeEach: function(assert) { | ||
mock.stop(); | ||
@@ -16,4 +16,4 @@ canRoute.defaultBinding = "mock"; | ||
test("Calling route.stop() tears down bindings", function(){ | ||
QUnit.stop(); | ||
QUnit.test("Calling route.stop() tears down bindings", function(assert) { | ||
var done = assert.async(); | ||
mock.start(); | ||
@@ -29,3 +29,3 @@ | ||
setTimeout(function(){ | ||
QUnit.equal(hash.get(), "home", "set to home"); | ||
assert.equal(hash.get(), "home", "set to home"); | ||
@@ -39,6 +39,6 @@ canRoute.stop(); | ||
setTimeout(function(){ | ||
QUnit.equal(hash.get(), "cart", "now it is the cart"); | ||
QUnit.start(); | ||
assert.equal(hash.get(), "cart", "now it is the cart"); | ||
done(); | ||
}, 30); | ||
}, 30); | ||
}); |
@@ -1,4 +0,4 @@ | ||
'use strict'; | ||
"use strict"; | ||
var testSauceLabs = require('test-saucelabs'); | ||
var testSauceLabs = require("test-saucelabs"); | ||
@@ -11,5 +11,5 @@ var maxDuration = 10800; // seconds, default 1800, max 10800 | ||
var platforms = [{ | ||
browserName: 'safari', | ||
platform: 'OS X 10.13', | ||
version: '11', | ||
browserName: "safari", | ||
platform: "OS X 10.13", | ||
version: "11", | ||
maxDuration: maxDuration, | ||
@@ -19,4 +19,4 @@ commandTimeout: commandTimeout, | ||
}, { | ||
browserName: 'MicrosoftEdge', | ||
platform: 'Windows 10', | ||
browserName: "MicrosoftEdge", | ||
platform: "Windows 10", | ||
maxDuration: maxDuration, | ||
@@ -26,5 +26,5 @@ commandTimeout: commandTimeout, | ||
}, { | ||
browserName: 'firefox', | ||
platform: 'Windows 10', | ||
version: 'latest', | ||
browserName: "firefox", | ||
platform: "Windows 10", | ||
version: "latest", | ||
maxDuration: maxDuration, | ||
@@ -34,5 +34,5 @@ commandTimeout: commandTimeout, | ||
}, { | ||
browserName: 'googlechrome', | ||
platform: 'OS X 10.12', | ||
version: 'latest', | ||
browserName: "googlechrome", | ||
platform: "OS X 10.12", | ||
version: "latest", | ||
maxDuration: maxDuration, | ||
@@ -43,3 +43,3 @@ commandTimeout: commandTimeout, | ||
browserName: 'Safari', | ||
'appium-version': '1.7.1', | ||
'appium-version': '1.9.1', | ||
platformName: 'iOS', | ||
@@ -55,8 +55,8 @@ platformVersion: '11.0', | ||
urls: [{ | ||
name: 'can-route', | ||
url: 'http://localhost:3000/test/test-ie.html?hidepassed', | ||
name: "can-route", | ||
url: "http://localhost:3000/test/test-ie.html?hidepassed", | ||
platforms: [{ | ||
browserName: 'internet explorer', | ||
platform: 'Windows 10', | ||
version: '11.0', | ||
browserName: "internet explorer", | ||
platform: "Windows 10", | ||
version: "11.0", | ||
maxDuration: maxDuration, | ||
@@ -67,4 +67,4 @@ commandTimeout: commandTimeout, | ||
}, { | ||
name: 'can-route', | ||
url: 'http://localhost:3000/test/test.html?hidepassed', | ||
name: "can-route", | ||
url: "http://localhost:3000/test/test.html?hidepassed", | ||
platforms: platforms | ||
@@ -71,0 +71,0 @@ }], |
@@ -1,3 +0,3 @@ | ||
var canRoute = require('can-route'); | ||
var QUnit = require('steal-qunit'); | ||
var canRoute = require("can-route"); | ||
var QUnit = require("steal-qunit"); | ||
var DefineMap = require("can-define/map/"); | ||
@@ -9,11 +9,11 @@ | ||
QUnit.module("can-route .url",{ | ||
setup: function(){ | ||
canRoute.routes = {}; | ||
} | ||
beforeEach: function(assert) { | ||
canRoute.routes = {}; | ||
} | ||
}); | ||
test(".url with merge=true (#16)", function(){ | ||
QUnit.stop(); | ||
var oldUsing = canRoute.urlData; | ||
var mock = canRoute.urlData = new RouteMock(); | ||
QUnit.test(".url with merge=true (#16)", function(assert) { | ||
var done = assert.async(); | ||
var oldUsing = canRoute.urlData; | ||
var mock = canRoute.urlData = new RouteMock(); | ||
var AppState = DefineMap.extend({seal: false},{"*": "stringOrObservable"}); | ||
@@ -26,18 +26,18 @@ var appState = new AppState({}); | ||
appState.update({'foo': 'bar',page: "recipe", id: 5}); | ||
appState.update({"foo": "bar",page: "recipe", id: 5}); | ||
canReflect.onValue(mock,function(){ | ||
QUnit.equal(canRoute.url({}, true), "#!&foo=bar&page=recipe&id=5", "empty"); | ||
QUnit.ok(canRoute.url({page: "recipe"}, true), "page:recipe is true"); | ||
canReflect.onValue(mock,function(){ | ||
assert.equal(canRoute.url({}, true), "#!&foo=bar&page=recipe&id=5", "empty"); | ||
assert.ok(canRoute.url({page: "recipe"}, true), "page:recipe is true"); | ||
QUnit.ok(canRoute.url({page: "recipe", id: 5}, true), "number to string works"); | ||
QUnit.ok(canRoute.url({page: "recipe", id: 6}, true), "not all equal"); | ||
assert.ok(canRoute.url({page: "recipe", id: 5}, true), "number to string works"); | ||
assert.ok(canRoute.url({page: "recipe", id: 6}, true), "not all equal"); | ||
setTimeout(function(){ | ||
canRoute.urlData = oldUsing; | ||
QUnit.start(); | ||
},20); | ||
setTimeout(function(){ | ||
canRoute.urlData = oldUsing; | ||
done(); | ||
},20); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
119506
52
2477
0