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

Custom asymmetric expect matchers aren't able to print Symbol arguments in error reports. #7534

Closed
Ross-Esmond opened this issue Dec 18, 2018 · 1 comment · Fixed by #9888
Labels

Comments

@Ross-Esmond
Copy link

Ross-Esmond commented Dec 18, 2018

🐛 Bug Report

If a symbol is used as an argument to an asymmetric matcher expect will fail when it tries to .join(', ') the arguments while printing the error report.

To Reproduce

There's no reason to want to do this specifically, but it does reproduce the issue.

expect.extend({
  toBeSymbol (received, symbol) {
    return {
      pass: received === symbol,
      message: () => ''
    }
  }
})

test('should throw', function () {
  const foo = Symbol('foo')
  const bar = Symbol('bar')

  expect({ a: foo }).toEqual({
    a: expect.toBeSymbol(bar)
  })
})

Expected behavior

Jest should be able to produce a clean diff which identifies the asymmetric matcher as: toBeSymbol<Symbol(bar)> but instead the expect package fails to build a diff and errors out with TypeError: Cannot convert a Symbol value to a string

Link to repl

repl.it demo Repl's standard Jest is version 22 so I had to import expect directly. Still isolates the issue.

I'll have a pull request soon. Even if it's not merged it'll still show exactly what the issue is. Having trouble building. Might have to postpone this. Apparently .join('') doesn't implicitly convert values to strings. So this line is failing when given a Symbol argument. maping the array toStrings fixes it.

@Ross-Esmond Ross-Esmond changed the title Custom asymmetric expect matchers aren't able to print Symbol samples in error reports. Custom asymmetric expect matchers aren't able to print Symbol arguments in error reports. Dec 18, 2018
ghostd added a commit to ghostd/jest that referenced this issue Apr 26, 2020
ghostd added a commit to ghostd/jest that referenced this issue Apr 26, 2020
ghostd added a commit to ghostd/jest that referenced this issue Apr 26, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant