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

Support magic-assert with other assertion libraries #1277

Closed
novemberborn opened this issue Feb 20, 2017 · 5 comments · Fixed by #3187
Closed

Support magic-assert with other assertion libraries #1277

novemberborn opened this issue Feb 20, 2017 · 5 comments · Fixed by #3187

Comments

@novemberborn
Copy link
Member

It'd be great if AVA could recognize assertion errors from other libraries and show similar output as it does for AVA's own assertions. See #1256 (comment).

@danny-andrews
Copy link
Contributor

I second this. I'm using the fantastic expect library, and I get unhappy error messages like the following:

  /Users/danny/Projects/circleci-weigh-in/node_modules/expect/lib/assert.js:29

  Error thrown in test:

  Error {
    message: 'Expected { threshold: { targets: \'yoyo.js\', maxSize: 2, strategy: \'any\' }, offendingAssets: [ \'yoyo.js\' ] } to match { message: \'"yoyo.js" (35B) must be less than or equal to 2B!\', threshold: { targets: \'yoyo.js\', maxSize: 2, strategy: \'any\' }, offendingAssets: [ \'yoyo.js\' ] }',
  }

  assert (node_modules/expect/lib/assert.js:29:9)
  Expectation.toMatch (node_modules/expect/lib/Expectation.js:138:28)
  _ramda2.default.forEach (tests/bundle-size-utils.test.js:115:33)
  forEach (node_modules/ramda/src/forEach.js:43:5)
  Object.f2 [as forEach] (node_modules/ramda/src/internal/_curry2.js:25:16)
  Test.fn (tests/bundle-size-utils.test.js:113:9)

when using expect.toMatch

@novemberborn novemberborn added the enhancement new functionality label Oct 26, 2017
@tryzniak
Copy link
Contributor

tryzniak commented Aug 21, 2019

Are we still after this one? I'd like to tackle it, but need some hints :)
Edit:
I guess we just need to detect and format assertion errors here

ava/lib/test.js

Lines 364 to 370 in 49b202f

if (!this.detectImproperThrows(result.error)) {
this.saveFirstError(new assert.AssertionError({
message: 'Error thrown in test',
savedError: result.error instanceof Error && result.error,
values: [formatErrorValue('Error thrown in test:', result.error)]
}));
}

@tryzniak
Copy link
Contributor

tryzniak commented Aug 21, 2019

Took a look at it and made some changes. What do you think about generation output as below? It for expect btw.
New version:
Screen Shot 2019-08-21 at 19 04 36

Old version:
Screen Shot 2019-08-21 at 19 08 52

@novemberborn
Copy link
Member Author

I think you're on to something here @tryzniak. Would you mind opening a PR for this?

@tryzniak
Copy link
Contributor

Sure! I'll do soon!

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

Successfully merging a pull request may close this issue.

4 participants