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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@mo mo Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants