-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjasmine.html
114 lines (90 loc) · 3.47 KB
/
jasmine.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="stylesheet" type="text/css" href="css/jasmine.css">
<!-- early genpayload dependencies (also needed in specs) -->
<script type="text/javascript" src="js/json2.js"></script>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<!-- jasmine -->
<script type="text/javascript" src="js/jasmine.js"></script>
<script type="text/javascript" src="js/jasmine-html.js"></script>
<script type="text/javascript" src="js/jasmine-jquery-1.3.1.js"></script>
<!-- specs -->
<script type="text/javascript" src="js/specs_test_docs.js"></script>
<script type="text/javascript" src="js/specs.js"></script>
<!-- genpayload dependencies (jquery also used below). -->
<script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.couch.js"></script>
<script type="text/javascript" src="js/timezone.js"></script>
<script type="text/javascript" src="js/all_zones.js"></script>
<script type="text/javascript" src="js/zone_list.js"></script>
<script type="text/javascript" src="js/init_timezone.js"></script>
<!-- bootstrap, setup, fixtures, go -->
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var blob = null, code = null, doc_ready = false;
var original_onerror = window.onerror, original_alert = window.alert;
// Only global modification genpayload.js makes is to window.onerror
beforeEach(function() {
var box = $("<div id='genpayload' />");
box.append(blob.clone());
$("body").append(box);
if (window.onerror != original_onerror)
throw "onerror protection failed";
spyOn(window, 'alert').andCallFake(function () {
// as a function, facilitates easy breakpointing
// tests can .andReturn(null) to stop it throwing
throw "unexpected alert";
});
spyOn($, 'ajax').andThrow("This should have been intercepted in jquery.couch");
var dbspy = spyOn($.couch, 'db').andCallFake(function () {
var db = jasmine.createSpyObj('couchdb', ['view', 'saveDoc', 'allDocs']);
dbspy.mostRecentFakeDatabase = db;
return db;
});
$.globalEval(code);
expect($.couch.db.calls.length).toEqual(1);
window.couchdbspy = dbspy.mostRecentFakeDatabase;
});
afterEach(function () {
$("#genpayload").remove();
window.onerror = original_onerror;
});
$(function() {
doc_ready = true;
loaded();
});
$.ajax({
url: "genpayload.html",
dataType: "text"
}).success(function (contents) {
blob = $(contents).not("script, link, title");
loaded();
});
$.ajax({
url: "js/genpayload.js",
dataType: "text"
}).success(function (contents) {
code = contents;
loaded();
});
function loaded() {
if (!doc_ready || blob === null || code === null)
return;
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>