-
Notifications
You must be signed in to change notification settings - Fork 3
/
dsl.js
136 lines (115 loc) · 3.25 KB
/
dsl.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* global describe, xdescribe, ddescribe, it, xit, iit,
expect, beforeEach, afterEach, spyOn, getCurrentSuite,
setCurrentSuite, getCurrentTest, setCurrentTest,
getCurrentReport, setCurrentReport, jasmine */
var any = require("./any");
var createSpy = require("./spy");
var createSpyObject = require("./spy-object");
// DEPRECATED
jasmine = {
createSpy: createSpy,
createSpyObj: createSpyObject,
any: any
};
// During declaration
var currentSuite;
// During execution
var currentReport;
var currentTest;
describe = function (name, callback) {
if (!currentSuite) {
throw new Error("Can't call describe when there is no active suite");
}
var suite = currentSuite.nestSuite(name);
suite.describe(callback);
};
xdescribe = function (name, callback) {
if (!currentSuite) {
throw new Error("Can't call xdescribe when there is no active suite");
}
var suite = currentSuite.nestSuite(name);
suite.skip = true;
suite.describe(callback);
};
ddescribe = function (name, callback) {
if (!currentSuite) {
throw new Error("Can't call ddescribe when there is no active suite");
}
var suite = currentSuite.nestSuite(name);
suite.setExclusive();
suite.describe(callback);
};
it = function (name, callback) {
if (!currentSuite) {
throw new Error("Can't call it when there is no active suite");
}
currentSuite.nestTest(name, callback);
};
iit = function (name, callback) {
if (!currentSuite) {
throw new Error("Can't call iit when there is no active suite");
}
var test = currentSuite.nestTest(name, callback);
currentSuite.setExclusive();
test.exclusive = true;
};
xit = function (name, callback) {
if (!currentSuite) {
throw new Error("Can't call xit when there is no active suite");
}
var test = currentSuite.nestTest(name, callback);
test.skip = true;
};
beforeEach = function (callback) {
if (!currentSuite) {
throw new Error("Cannot use `beforeEach` outside of a 'define' block");
}
currentSuite.beforeEach = callback;
};
afterEach = function (callback) {
if (!currentSuite) {
throw new Error("Cannot use `afterEach` outside of a 'define' block");
}
currentSuite.afterEach = callback;
};
expect = function (value) {
if (!currentReport) {
throw new Error("Cannot declare an expectation outside of an 'it' block");
}
if (value && typeof value.expect === "function") {
return value.expect(currentReport, currentTest);
} else {
return new currentTest.suite.Expectation(
value,
currentReport,
currentTest
);
}
};
spyOn = function (object, name) {
object[name] = createSpy(name, object[name]);
return object[name];
};
// For internal linkage
getCurrentSuite = function () {
if (currentSuite) {
return currentSuite;
} else if (currentTest) {
return currentTest.suite;
}
};
setCurrentSuite = function (suite) {
currentSuite = suite;
};
getCurrentReport = function () {
return currentReport;
};
setCurrentReport = function (report) {
currentReport = report;
};
getCurrentTest = function () {
return currentTest;
};
setCurrentTest = function (test) {
currentTest = test;
};