-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathqunit.cli.txt
159 lines (144 loc) · 13 KB
/
qunit.cli.txt
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
┏━━━━━━━━━━━┓
┃ QUNIT ┃
┗━━━━━━━━━━━┛
ALTERNATIVES ==> #See Mocha
LIBRARY ==> #Unit testing 0.7.1
#Can use CDN at http://code.jquery.com/qunit/
#Also need to link qunit.css.
RESULTS ==> #Either:
# - in an HTML page (loading JavaScript code), with two <div> with ID
# qunit and qunit-fixture, where the results appear.
# - to check "Hide passed tests" by def, do QUnit.config.hidepassed = true
# at page load.
# - using callbacks done(CALLBACK), etc. (see below)
TESTS START ==> #Test will not fire before WINDOW load event.
#To control even more, do QUnit.config.autostart = false, then call
#QUnit.start() when ready.
PAVLOV ==> #QUnit should be used with Pavlov plugin which gives it a BDD approach.
#The Pavlov equivalents are in this doc when possible.
#For others, see following list:
# - module(STR[, { setup: FUNC(), teardown: FUNC }]) = describe(STR) and
# before|after(STR)
# - test(...) = it(...)
# - [not]propEqual(...) = assert(...).is[Not]SameAs(...)
# - [not][strict]equal(...) = assert(...).is[Not][Strictly]EqualTo(...)
# - ok(...) = assert(...).isTrue(...)
# - throws(...) = assert(...).throwsException(...)
# - QUnit.cases(...) = given(...)
# - QUNITCASES.test(...) = QUNITCASES.it(...)
# - asyncTest(...): like async(...) but used as test(...)
pavlov.specify(STR, FUNC()) #Top-level function, where describe() should be put.
describe(STR) #Starts a test suite called STR (déf: "").
#Can nest describe().
#To run only a specific module, do QUnit.config.module = STR at page load.
it(STR[, FUNC()]) #Starts a test case called STR.
#To do async. (avoid when possible):
# - use setTimeout(...,0) inside FUNC()
# - Use async(FUNC()) around each async. FUNC()
# - in each async. callback, finish by resume()
# Test considered finished when all resume() called.
#Test unit can begin with expect(NUM) to declare the number of assertions.
#FUNC is optional, so can write a test to complete (will fail with
#"not implemented")
assert(BOOL).isTrue|False(STR) #Asserts BOOL. STR is description.
assert.pass|fail(STR) #Same as assert(BOOL).isTrue(true|false)
assert(VAL).is[Not]Null(STR) #Asserts VAL === !== null
assert(VAL).is[Un]Defined(STR) #Asserts typeof VAL === !== 'undefined'
assert(VAL).is[Not]Function(STR) #Asserts VAL is [not] a FUNC
assert(VAL).is[Not]EqualTo(VAL2, STR) #Asserts VAL == != VAL2.
assert(VAL).is[Not]StrictlyEqualTo(VAL2, STR) #Asserts VAL === !== VAL2.
assert(OBJ).is[Not]SameAs(OBJ2, STR) #Asserts that OBJ is reference to OBJ2.
[not]propEqual(OBJ, OBJ2, STR) #Asserts that OBJ have same keys, with same values, by copy, without comparing
#the prototypes.
assert(FUNC()).throwsException([ERROR, ]STR) #Asserts that FUNC() throws.
#Can target specifically ERROR, or REGEXP.test(ERROR.name)
pavlov.specify.extendAssertions(OBJ) #Creates new assertion { ASSERTION: FUNC(VAL..., STR) }:
# - FUNC should call ok(TEST, STR)
# - FUNC name should be self explanatory for error messages
# - can be fired as assert(VAL).ASSERTION([...,][STR])
log(CALLBACK(OBJ)) #Register a CALLBACK fired after each assertion, where OBJ has members:
# - result BOOL: true if passed
# - actual|expected VAL: first and second argument (with *equal())
# - message STR
# - source STR: error message printed on console
# - module STR: module name
# - name STR: test name
testStart(CALLBACK(OBJ)) #Register a CALLBACK fired before each test, where OBJ has members name STR
#and module STR.
testDone(CALLBACK(OBJ)) #Register a CALLBACK fired after each test, where OBJ has members:
# - failed|passed|total UINT: number of tests
# - duration UINT: in ms
# - module STR, name STR: like log()
before|after(CALLBACK()) #Same but:
# - without the OBJ
# - more BDD name
# - if nested describe(), fired before|after them too
moduleStart(CALLBACK(OBJ)) #Register a CALLBACK fired before each module, where OBJ has members name STR.
moduleDone(CALLBACK(OBJ)) #Register a CALLBACK fired after each module, where OBJ has members name STR,
#failed|passed|total UINT.
begin(CALLBACK()) #Register a CALLBACK fired before all modules.
#Must be registered at page load.
done(CALLBACK(OBJ)) #Register a CALLBACK fired after all modules, where OBJ has members
#failed|passed|total UINT, and runtime UINT.
#Will fire once at page load end (if some tests were performed), and then
#once for each <script> run.
phantomjs runner.js FILE.html [TIMEOUT] ##Run tests using phantomjs (so doesn't require browser), and prints
##result on stdout.
##TIMEOUT is 1000ms by def.
QUNIT-PARAMETERIZE ==> ##Plugin for data-driven testing (also exists on npm)
##To make it Pavlov-compatible, replace given() method in source code by:
## given: function(testCases) {
## var cases = QUnit.cases(testCases);
## cases.it = cases.test;
## return cases;
## },
given(OBJ_ARR) ##Returns QUNITCASES
QUNITCASES.it(STR, FUNC(OBJ2)) ##Like test(...), but FUNC() will:
## - run OBJ_ARR.length times
## - each run will get an OBJ, that can be accessed with OBJ2.*
##So each OBJ are similar data (same keys), but different values.
##If OBJ.title exist, will be appended to test name.
##Can chain several .test(...).test(...) on same cases(...)
QUNITCASES.sequential(OBJ3_ARR) ##Merge each OBJ3 into each OBJ, one after another.
##OBJ.title will be concatenated.
##Returns QUNITCASES.
QUNITCASES.combinatorial(OBJ3_ARR) ##Modify OBJ to the cartesian product of OBJ and OBJ3.
MOCKJAX ==> ##Allow create mock AJAX requests (e.g. to not implemented yet REST APIs) that
##are easy to remove once they can be actually sent.
##mocks should be created at beginning of test, and removed at end of it.
$.mockjax(OBJ) ##From now on, all $.ajax(STR, OBJ2) whose STR matches OBJ2.url, will return
##response specified by OBJ instead, which members are:
## - url: can be a STR (matches full URL, can contain "*") or a REGEXP
## (partial match)
## - urlParams STR_ARR: match GET variables
## - data VAL: matches when using data VAL with $.ajax()
## - type STR: same
## - headers OBJ: response headers
## - lastModified STR
## - etag STR
## - status UINT (déf: 200) and statusText: response status code|text
## - responseTime UINT (déf: 500): how long to wait before responding (in ms)
## - isTimeout BOOL: if true, like putting unlimited responseTime
## - contentType STR (déf: "text/plain"): response MIME type
## - response can be specified with:
## - responseText STR|OBJ
## - responseXML STR
## - response FUNC(OBJ2), returning STR|OBJ, where OBJ2 are $.ajax(OBJ2)
## - proxy STR: returned file STR content
##Returns a MOCKJAXID
$.mockjax(FUNC(OBJ2)) ##More flexible way: OBJ2 is $.ajax(OBJ2), and FUNC() must return OBJ
##of $.mockjax(OBJ) if OBJ2 match specific criteria.
$.mockjaxClear([MOCKJAXID]) ##Removes a mock (def: all)
$.mockjax.mockedAjaxCalls() ##Returns all mocks as OBJ_ARR
$.mockjaxSettings ##Default values for OBJ of $.mockjax(OBJ)
DEXTER ==> ##
Dexter.fake(VAR, STR[, FUNC(...)]) ##Creates a function VAR.STR = FUNC(...), and return a FAKE.
##VAR.STR should be an existing FUNC.
##If no FUNC, can still declare it later with FAKE.callback = FUNC
##Fakes should be done at beginning of test, and erased at end.
##Can check how many times called with FAKE.called
Dexter.spy(...) ##Same as Dexter.fake(), but calls spy also after original FUNC, and not
##instead of original FUNC.
##Can check how many times called with SPY.called
FAKE|SPY.restore() ##Erase effect.
Dexter.stored ##Array of all FAKE|SPY