postman-app-support
postman-app-support copied to clipboard
Test errors should show more information
App Details:
Postman for Mac
Version 5.3.2
OS X 17.3.0 / x64
Issue Report:
- Did you encounter this recently, or has this bug always been there: It's been there as long as I've been using the app.
- Expected behaviour:
When there's an error with the tests, it should show more information. For example, as shown in the screenshot below, if a test is looking for something in the JSON response and can't find it, the error should include the line number in the tests or something. Like if inside the tests, line number 58 is looking for data.total_balance, and the total_balance node isn't returned, it should say
There was an error in evaluating the test script *in line 58*
followed by the message. Essentially it should just tell me where the error is. Because I have a lot of tests, and the response is very large, so to try to figure out just which node wasn't returned that's causing this error takes a lot of searching, when it could be made so much simpler by just putting the line number. - Console logs (http://blog.getpostman.com/2014/01/27/enabling-chrome-developer-tools-inside-postman/ for the Chrome App, View->Toggle Dev Tools for the Mac app):
- Screenshots (if applicable)
Put this line in the tests for any call that wouldn't return this node var keys = Object.keys(data.account).length;
When you send the call, the tests will fail and show the same message as in the screenshot above.
Since you know what you're looking for, it's easy. But when there's a lot of instances similar to this in the tests, it gets very hard to find out which one is breaking the tests.
Thanks for raising your hand on a feature, yes indeed this in our list of things to be done, we shall update the thread when we take it.
Suggested workaround until this issue is addressed: use the second parameter to .expect() which is a "custom error message to show when the assertion fails".
This old code:
pm.test('Name is a minimum of 3 characters', pm.expect(name).to.have.lengthOf.above(2));
...fails with cryptic error message "AssertionError: expected 'NA' to have a length above 2 but got 2".
This new code:
td = 'Name is a minimum of 3 characters';
pm.test(td, pm.expect(name, 'FAILED:['+td+']').to.have.lengthOf.above(2));
...fails with "AssertionError: FAILED:[Name is a minimum of 3 characters]: expected 'NA' to have a length above 2 but got 2".
The failure is much more descriptive now. Does this not (temporarily) solve the issue?
Note: The error details forwarded from inside the sandbox maybe placed closer to the failure.
any update would be helpful ... in addition if you just got the line number it failed would be helpful rather than the generic cannot find/convert
It should be fairly simply to implement this feature.
Given this class, for example:
class Warning extends Error { constructor(message) { super(message); this.name = "Warning - line " + this.lineNumber; } }
Why should I not be able to execute:
if (!foo && !bar) throw new Warning("Unexpected criteria");
Expected output:
// "Warning - line 10: Unexpected criteria"
I understand this is only available in Firefox at the moment - but, please... Do implement this quite simple feature.
My workaround, for anyone interested in printing line numbers to console...
class Warning extends Error { constructor(message) { super(message); this.name = "Warning @ " + getLineNumber(this.stack); } }
if (!foo && !bar) throw new Warning("Unexpected criteria");
Output: // Warning @ 229:23: Unexpected criteria
function getLineNumber(stack) { var regEx = /\.eval \(eval at exec \(evalmachine\.<anonymous>(\S+)\), <anonymous>:([0-9]+):([0-9]+)/; return stack.split("\n")[1].match(regEx)[2] + ":" + stack.split("\n")[1].match(regEx)[3]; }
Please impl ASAP.
GPT6 pls fix when you have a spare millisecond
It's been nearly seven years! Please implement this ASAP