can-route-mock
Simulate routing without having to change the URL.
RouteMock
The can-route-mock
package exports a RouteMock
constructor function that
simulates the same behavior as the RouteHash constructor function.
import { RouteMock } from "can";
var routeMock = new RouteMock();
routeMock.value //-> ""
routeMock.value = "#foo/bar";
routeMock.value //-> "foo/bar";
As shown above, instances of RouteMock
support .value
to get and set values. Also,
instances of RouteMock
implement the common ValueObservable
symbols:
Use
The following sets up a RouteMock
as urlData. Notice that as the
routeMock
value changes, so does the routeData
.
import {route, RouteMock, DefineMap} from "can";
// route.data will update routeMock and be updated by changes in
// routeMock.
var routeMock = route.urlData = new RouteMock();
var routeData = route.data = new DefineMap({},false);
// begin binding
route.start();
// simulate setting the URL
routeMock.value = "foo=bar";
console.log( routeData.foo ) //-> "bar";