double async check
[mkws-moved-to-github.git] / test / spec / async.spec.js
1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
2  *
3  * async check
4  *
5  */
6 describe("Asynchronous check", function () {
7     it("contains spec with an expectation", function () {
8         expect(true).toBe(true);
9     });
10
11     // Asynchronous part
12     it("simple check", function () {
13         var max_time = 1;
14         var timer = 0;
15
16         function found(time, none) {
17             setTimeout(function () {
18                 timer = time;
19             }, time * 1000);
20         }
21
22         runs(function () {
23             // check hit counter after N seconds
24             found(0, true);
25             found(0.2);
26             found(0.4);
27             found(0.5);
28             found(0.7);
29             found(max_time);
30         });
31
32         waitsFor(function () {
33             // console.log("waits for ... " + timer);
34             return timer == max_time ? true : false;
35         }, "The Value should be N seconds", max_time * 1000);
36
37         runs(function () {
38             expect(timer).toEqual(max_time);
39         });
40     });
41
42
43     it("double async check", function () {
44         var max_time = 0.5;
45         var timer = 0;
46
47         function found(time, none) {
48             setTimeout(function () {
49                 timer = time;
50             }, time * 1000);
51         }
52
53         runs(function () {
54             found(0);
55             found(0.2);
56             found(max_time - 0.1);
57         });
58
59         waitsFor(function () {
60             return timer == max_time - 0.1 ? true : false;
61         }, "The Value should be N seconds", max_time * 1000);
62
63         runs(function () {
64             expect(timer <= max_time).toBeTruthy();
65         });
66
67         timer = 0;
68         runs(function () {
69             found(0.1);
70             found(max_time);
71         });
72
73         waitsFor(function () {
74             // console.log("waits for ... " + timer);
75             return timer == max_time ? true : false;
76         }, "The Value should be N seconds", max_time * 1000);
77
78         runs(function () {
79             expect(timer <= max_time).toBeTruthy();
80         });
81     });
82
83 });