-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.js
57 lines (55 loc) · 2.08 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
dojo.provide('tests');
dojo.require('urldispatch');
dojo.require('urldispatch.MissingArgumentError');
dojo.require('urldispatch.RouteNotFoundError');
doh.register('tests.urldispatchTestGroup', [
{
name: 'reverseTest',
setUp: function(){
this.routes = [
['/', function() {}, 'home'],
['/Hello/:name', function() {}, 'hello']
];
this.dispatcher = new urldispatch.Dispatcher(this.routes);
},
runTest: function(){
doh.is('/', this.dispatcher.reverse('home'));
doh.is('/Hello/Kerli', this.dispatcher.reverse('hello', {name: 'Kerli'}));
doh.e(urldispatch.MissingArgumentError, this.dispatcher, 'reverse', ['hello', {}]);
doh.e(urldispatch.MissingArgumentError, this.dispatcher, 'reverse', ['hello']);
doh.e(urldispatch.RouteNotFoundError, this.dispatcher, 'reverse', ['unknown_name']);
}
},
{
name: 'routeMatchTest',
setUp: function(){
this.testViews = {
root: 0,
hello: 0
};
this.routes = [
['!/', dojo.hitch(this, function(){ this.testViews.root++; }), 'home'],
['!/Hello', dojo.hitch(this, function() { this.testViews.hello++; }), 'hello']
];
this.dispatcher = new urldispatch.Dispatcher(this.routes);
},
runTest: function(){
var testViews = this.testViews;
doh.is(0, testViews.root);
this.dispatcher.dispatch("!/");
doh.is(1, testViews.root);
this.dispatcher.dispatch("!/Hello");
doh.is(1, testViews.root);
doh.is(1, testViews.hello);
this.dispatcher.dispatch("!/");
doh.is(2, testViews.root);
doh.is(1, testViews.hello);
this.dispatcher.dispatch("!/Hello");
doh.is(2, testViews.root);
doh.is(2, testViews.hello);
this.dispatcher.dispatch("!/");
doh.is(3, testViews.root);
doh.is(2, testViews.hello);
}
}
]);