Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporter: Print "actual:", "expected:" even if they are undefined #102

Merged
merged 2 commits into from Jun 2, 2017
Merged

Conversation

@mo
Copy link
Contributor

@mo mo commented May 17, 2017

If "foo" was expected but the actual value was undefined, then print:

actual: undefined
expected: "foo"

If undefined was expected but "foo" was returned, then we print:

actual: "foo"
expected: undefined

NOTE: When "actual" and "expected" are both undefined, the error
being logged is not one comparing two values, for example:

message: "Too many calls to the assert.async callback"
severity: failed

Copy link
Member

@trentmwillis trentmwillis left a comment

I think there is a simpler approach here. We should simply check if (error.hasOwnProperty('actual')) { (similarly for expected as well).

Also, would you mind adding a unit test for this edge case?

if (error.actual) {
console.log(` actual: ${JSON.stringify(error.actual, null, 2)}`)
if (error.hasOwnProperty('actual')) {
var actualStr = error.actual ? JSON.stringify(error.actual, null, 2) : 'undefined'

This comment has been minimized.

@trentmwillis

trentmwillis Jun 1, 2017
Member

This check should be stricter, otherwise we'll get undefined for any "falsy" value.

This comment has been minimized.

@mo

mo Jun 1, 2017
Author Contributor

Ah good catch! Fixed now.

If "foo" was expected but the actual value was undefined, then print:

  actual: undefined
  expected: "foo"

If undefined was expected but "foo" was returned, then we print:

  actual: "foo"
  expected: undefined

NOTE: When "actual" and "expected" are both undefined, the error
being logged is not one comparing two values, for example:

  message: "Too many calls to the `assert.async` callback"
  severity: failed
Copy link
Member

@trentmwillis trentmwillis left a comment

Thanks! There are likely still edge cases, but we can tackle those as they come up

@trentmwillis trentmwillis merged commit fe86a1b into js-reporters:master Jun 2, 2017
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants