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

Does not handle objects without prototype #148

Open
fatso83 opened this issue Nov 20, 2019 · 2 comments
Open

Does not handle objects without prototype #148

fatso83 opened this issue Nov 20, 2019 · 2 comments

Comments

@fatso83
Copy link
Contributor

fatso83 commented Nov 20, 2019

  • library version : 3.2.0
  • Environment : Node

What did you expect to happen?
That it would print a normal assertion error

What actually happens
It fails with

TypeError: Cannot convert object to primitive value
    at String (<anonymous>)
    at /tmp/test1/node_modules/@sinonjs/referee/lib/interpolate-pos-arg.js:12:44
    at Array.reduce (<anonymous>)
    at interpolatePosArg (/tmp/test1/node_modules/@sinonjs/referee/lib/interpolate-pos-arg.js:9:12)
    at Object.fail (/tmp/test1/node_modules/@sinonjs/referee/lib/define-assertion.js:30:27)
    at assertion (/tmp/test1/node_modules/@sinonjs/referee/lib/define-assertion.js:68:17)
    at Function.referee.<computed>.<computed> [as isUndefined] (/tmp/test1/node_modules/@sinonjs/referee/lib/define-assertion.js:93:26)
    at Object.<anonymous> (/tmp/test1/mytest.js:4:8)

How to reproduce

$ cat > mytest.js  << EOF
var referee = require("@sinonjs/referee");
var assert = referee.assert;

assert.isUndefined(Object.create(null));
EOF

node mytest.js 
@fatso83
Copy link
Contributor Author

fatso83 commented Nov 20, 2019

A way to fix this is for interpolate to check if the object has a toString method and default to using JSON.stringify(value).

@mantoni
Copy link
Member

mantoni commented Nov 28, 2019

Alternatively, we could prepare values with Object.prototype.toString.call(value).

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

No branches or pull requests

2 participants