Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 767c306

Browse files
DavidMikeSimonjuliemr
authored andcommitted
fix(jasminewd): include full pre-async-call stack trace in expectation failure message
1 parent 41feaca commit 767c306

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

debugging/failure_spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ describe('modes of failure', function() {
1515
var nonExistant = element(by.binding('nopenopenope')).getText();
1616
});
1717

18+
it('should fail to click a hidden element', function () {
19+
browser.get('index.html#/form');
20+
element(by.id("hiddenbutton")).click();
21+
});
22+
1823
it('should fail to use protractor on a non-Angular site', function() {
1924
browser.get('http://www.google.com');
2025
}, 20000);

jasminewd/index.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function seal(fn) {
1919
};
2020
};
2121

22-
2322
/**
2423
* Wraps a function so it runs inside a webdriver.promise.ControlFlow and
2524
* waits for the flow to complete before continuing.
@@ -28,6 +27,20 @@ function seal(fn) {
2827
*/
2928
function wrapInControlFlow(globalFn) {
3029
return function() {
30+
var driverError = new Error();
31+
driverError.stack = driverError.stack.replace(/ +at.+jasminewd.+\n/, '');
32+
33+
function asyncTestFn(fn) {
34+
return function(done) {
35+
var thing = flow.execute(function() {
36+
fn.call(jasmine.getEnv().currentSpec);
37+
}).then(seal(done), function(e) {
38+
e.stack = driverError.stack;
39+
done(e);
40+
});
41+
};
42+
};
43+
3144
switch (arguments.length) {
3245
case 1:
3346
globalFn(asyncTestFn(arguments[0]));
@@ -47,14 +60,6 @@ function wrapInControlFlow(globalFn) {
4760
throw Error('Invalid # arguments: ' + arguments.length);
4861
}
4962
};
50-
51-
function asyncTestFn(fn) {
52-
return function(done) {
53-
flow.execute(function() {
54-
fn.call(jasmine.getEnv().currentSpec);
55-
}).then(seal(done), done);
56-
};
57-
};
5863
};
5964

6065
global.it = wrapInControlFlow(global.it);
@@ -73,6 +78,8 @@ global.afterEach = wrapInControlFlow(global.afterEach);
7378
function wrapMatcher(matcher, actualPromise, not) {
7479
return function() {
7580
var originalArgs = arguments;
81+
var matchError = new Error("Failed expectation");
82+
matchError.stack = matchError.stack.replace(/ +at.+jasminewd.+\n/, '');
7683
actualPromise.then(function(actual) {
7784
var expected = originalArgs[0];
7885
if (expected instanceof webdriver.promise.Promise) {
@@ -92,7 +99,14 @@ function wrapMatcher(matcher, actualPromise, not) {
9299
if (not) {
93100
expectation = expectation.not;
94101
}
102+
var origFn = expectation.spec.addMatcherResult;
103+
var error = matchError;
104+
expectation.spec.addMatcherResult = function(result) {
105+
result.trace = error;
106+
jasmine.Spec.prototype.addMatcherResult.call(this, result);
107+
}
95108
expectation[matcher].apply(expectation, originalArgs);
109+
expectation.spec.addMatcherResult = origFn;
96110
}
97111
});
98112
};

testapp/form/form.html

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ <h4>Buttons</h4>
6666
<button id="exacttext">Exact text</button>
6767
<button id="otherbutton">Partial button text</button>
6868
<button id="trapbutton">No match</button>
69+
<button id="hiddenbutton" style="display:none">Can't see me!</button>
6970
<input type="submit" value="Exact text" id="submitbutton"/>
7071
<input type="button" value="Hello text" id="inputbutton"/>
7172
</div>

0 commit comments

Comments
 (0)