Merge pull request #1374 from mattbrooks2010/master

Added missing tests.
This commit is contained in:
Masahiro Wakame
2013-12-04 06:28:14 -08:00
2 changed files with 58 additions and 1 deletions

57
routie/routie-tests.ts Normal file
View File

@@ -0,0 +1,57 @@
/// <reference path="routie.d.ts" />
// BASIC
// There are three ways to call routie. Here is the most basic way:
routie("users", function () {
// This gets called when hash == #users
});
// If you want to define multiple routes you can pass in an object like this:
routie({
"users": function () {
},
"about": function () {
}
});
// If you want to trigger a route manually, you can call routie like this:
routie("users/bob"); // window.location.hash will be #users/bob
// ADVANCED
// Routie also supports regex style routes, so you can do advanced routing like this:
routie("users/:name", function (name) {
// name == "bob";
});
routie("users/bob");
// Optional params:
routie("users/?:name", function (name) {
//name == undefined
//then
//name == bob
});
routie("users/");
routie("users/bob");
// Wildcard:
routie("users/*", function () {
});
routie("users/12312312");
// Catch all:
routie("*", function () {
});
routie("anything");

2
routie/routie.d.ts vendored
View File

@@ -4,7 +4,7 @@
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface Route {
constructor(path: string, name: string);
constructor(path: string, name: string): Route;
addHandler(fn: Function): void;
removeHandler(fn: Function): void;
run(params: any): void;