forked from dfkaye/where.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqunit-strategy.js
71 lines (56 loc) · 2.02 KB
/
qunit-strategy.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
// STRATEGY for QUnit ~ surprisingly not bad! however, complete interception
// of expected failures is not possible in the HTML Reporter as currently
// implemented (QUnit v1.13 as of this writing 12-FEB-2014.
//
// requires context argument with strategy defined as { QUnit: QUnit }
where.strategy('QUnit', function qunitStrategy(context) {
// this code reminds me of java for some reason...
var QUnit = context.QUnit;
var test;
var realPush;
var interceptingPush;
if (context.intercept) {
/*
* this block attempts to capture failing assertions, reset them to
* passing (i.e., they are expected to fail), and push them to QUnit's
* assertions list with the real 'push()' method.
*/
interceptingPush = function overridingAssertionsPush(details) {
if (!details.result) {
details.result = !details.result;
}
realPush.call(QUnit.config.current.assertions, details);
};
// override on start
QUnit.testStart(function(detail) {
realPush = QUnit.config.current.assertions.push;
QUnit.config.current.assertions.push = interceptingPush;
});
// undo override on done
QUnit.testDone(function(detail) {
QUnit.config.current.assertions.push = realPush;
});
}
QUnit.log(function onResult(details) {
if (!details.result) {
/*
* johann sonntagbauer fix 15 MAR 2015
* the strategy will be called initial with test.result = 'Passed'
* therefore reset the test result
*/
if (test.result === 'Passed') {
test.result = '';
}
test.result += 'Error: expected ' + details.actual + ' to be ' +
details.expected + '. ';
if (!context.intercept) {
// this adds the QUnit sourceFromStacktrace() output
test.result += '\n' + details.source;
}
}
});
return function testQUnit(fnTest, thisTest, value) {
test = thisTest;
fnTest.apply({}, [context].concat(value));
};
});