Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Cannot distinguish between generated and manually specified assertion messages #5836

Closed
glenjamin opened this issue Jul 12, 2013 · 4 comments

Comments

@glenjamin
Copy link

Since 6101eb1 landed.

AssertionError can take message, expected and actual options, if message is not passed, it gets generated from expected and actual.

Within test runner output, this leads to some duplication in the output:

     this.assert.strictEqual('1', 1);
       "1" === 1
       expected: 1
            got: '1'

Ideally I'd like to only display the expected and actual, unless a custom message has been passed - but as it stands I can't see any way to tell the difference.

@tjfontaine
Copy link

I'm confused by your request, are you complaining about how your choice of test runner handles the assertions in v0.11? Because without a custom message our assertion generates

> assert.strictEqual('1', 1)
AssertionError: "1" === 1
    at repl:1:9
    at REPLServer.defaultEval (repl.js:116:21)
    at REPLServer.b [as eval] (domain.js:183:18)
    at Interface.<anonymous> (repl.js:253:12)
    at Interface.EventEmitter.emit (events.js:100:17)
    at Interface._onLine (readline.js:195:10)
    at Interface._line (readline.js:524:8)
    at Interface._ttyWrite (readline.js:799:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:103:17)

and with

assert.strictEqual('1', 1, "Foo bar")
AssertionError: Foo bar
    at repl:1:9
    at REPLServer.defaultEval (repl.js:116:21)
    at REPLServer.b [as eval] (domain.js:183:18)
    at Interface.<anonymous> (repl.js:253:12)
    at Interface.EventEmitter.emit (events.js:100:17)
    at Interface._onLine (readline.js:195:10)
    at Interface._line (readline.js:524:8)
    at Interface._ttyWrite (readline.js:799:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:103:17)

@glenjamin
Copy link
Author

The key point is that a test runner can read the expected, operator and
actual properties to produce a much nicer display of the failure reason.

As it stands there's no way to tell if the message property is useless
duplication or necessary context

On 27 Jul 2013, at 20:48, Timothy J Fontaine notifications@github.com
wrote:

I'm confused by your request, are you complaining about how your choice of
test runner handles the assertions in v0.11? Because without a custom
message our assertion generates

assert.strictEqual('1', 1)
AssertionError: "1" === 1
at repl:1:9
at REPLServer.defaultEval (repl.js:116:21)
at REPLServer.b as eval
at Interface. (repl.js:253:12)
at Interface.EventEmitter.emit (events.js:100:17)
at Interface._onLine (readline.js:195:10)
at Interface._line (readline.js:524:8)
at Interface._ttyWrite (readline.js:799:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:103:17)

and with

assert.strictEqual('1', 1, "Foo bar")
AssertionError: Foo bar
at repl:1:9
at REPLServer.defaultEval (repl.js:116:21)
at REPLServer.b as eval
at Interface. (repl.js:253:12)
at Interface.EventEmitter.emit (events.js:100:17)
at Interface._onLine (readline.js:195:10)
at Interface._line (readline.js:524:8)
at Interface._ttyWrite (readline.js:799:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:103:17)


Reply to this email directly or view it on
GitHubhttps://github.com//issues/5836#issuecomment-21671374
.

@tjfontaine
Copy link

Ok, so you want possibly a flag on AssertionError that indicates default message or not, that seems reasonable mind submitting a PR for it?

@glenjamin
Copy link
Author

Seems like a sensible approach, I'll whip something up

On 27 Jul 2013, at 21:11, Timothy J Fontaine notifications@github.com
wrote:

Ok, so you want possibly a flag on AssertionError that indicates
defaultmessage or not, that seems reasonable mind submitting a PR for
it?


Reply to this email directly or view it on
GitHubhttps://github.com//issues/5836#issuecomment-21671684
.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants