Skip to content

Commit a73f8d0

Browse files
committed
Merge pull request #1 from kplaube/master
Melhorias nos testes Jasmine
2 parents 00af1b1 + 0482c03 commit a73f8d0

File tree

2 files changed

+62
-54
lines changed

2 files changed

+62
-54
lines changed

tests/jasmine/SpecRunner.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<script type="text/javascript" src="lib/jasmine-1.2.0.rc3/jasmine-html.js"></script>
1111

1212
<!-- include source files here... -->
13-
<script type="text/javascript" src="spec/SpecHelper.js"></script>
14-
<script type="text/javascript" src="spec/jsRouteSpec.js"></script>
13+
<script type="text/javascript" src="../../jsRoute.js"></script>
1514

1615
<!-- include spec files here... -->
17-
<script type="text/javascript" src="../../jsRoute.js"></script>
16+
<script type="text/javascript" src="spec/SpecHelper.js"></script>
17+
<script type="text/javascript" src="spec/jsRouteSpec.js"></script>
1818

1919
<script type="text/javascript">
2020
(function() {

tests/jasmine/spec/jsRouteSpec.js

+59-51
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,59 @@
1-
describe("jsRoute", function() {
2-
3-
beforeEach(function() {
4-
5-
});
6-
7-
it("should be able to add routes", function() {
8-
route.add('^$', function(){self.x = self.x+1;});
9-
expect(route.routes.indexOf("^$") > -1).toBeTruthy();
10-
});
11-
12-
it("should be able to init routing", function() {
13-
location.hash="#22-10-2012";
14-
15-
route.add('^\\d{1,2}\\-\\d{1,2}\-\\d{4}$', function(x){
16-
if(x==='22-10-2012'){
17-
location.hash='#alterado';
18-
}
19-
});
20-
21-
runs(function(){
22-
route.init();
23-
});
24-
25-
waits(1000);
26-
27-
runs(function(){
28-
expect(location.hash).toEqual('#alterado');
29-
});
30-
31-
});
32-
33-
it("should be able to force a route", function() {
34-
route.add('^\\d{1,2}\\-\\d{1,2}\-\\d{4}$', function(x){
35-
if(x==='23-10-2012'){
36-
location.hash='#alterado';
37-
}
38-
});
39-
40-
runs(function(){
41-
route.call('#23-10-2012');
42-
});
43-
44-
waits(1000);
45-
46-
runs(function(){
47-
expect(location.hash).toEqual('#alterado');
48-
});
49-
50-
});
51-
});
1+
/*global describe, afterEach, beforeEach, it, expect, runs, waits, window, route*/
2+
3+
(function (window, route) {
4+
5+
'use strict';
6+
7+
describe("jsRoute", function () {
8+
9+
var self = this;
10+
11+
beforeEach(function () {
12+
route.routes = [];
13+
route.funcs = [];
14+
self.hash = false;
15+
window.clearInterval(route.interval);
16+
});
17+
18+
it("should be able to add routes", function () {
19+
route.add('^$', function () {
20+
self.x = self.x + 1;
21+
});
22+
expect(route.routes.indexOf("^$") > -1).toBeTruthy();
23+
});
24+
25+
it("should be able to init routing", function () {
26+
window.location.hash = "#22-10-2012";
27+
28+
route.add('^\\d{1,2}-\\d{1,2}-\\d{4}$', function (day) {
29+
self.hash = day;
30+
});
31+
32+
route.init();
33+
34+
waits(1000);
35+
36+
runs(function () {
37+
expect('22-10-2012').toEqual(self.hash);
38+
});
39+
});
40+
41+
it("should be able to force a route", function () {
42+
route.add('^\\d{1,2}-\\d{1,2}-\\d{4}$', function (day) {
43+
self.hash = day;
44+
});
45+
46+
route.call('23-10-2012');
47+
expect('23-10-2012').toEqual(self.hash);
48+
});
49+
50+
it("should be able to use pure regexp as route", function () {
51+
route.add(/^\d{1,2}-\d{1,2}-\d{4}$/, function (day) {
52+
self.hash = day;
53+
});
54+
55+
route.call('24-08-2012');
56+
expect('24-08-2012').toEqual(self.hash);
57+
});
58+
});
59+
}(window, route));

0 commit comments

Comments
 (0)