-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
Type check for parsePath variable would be nice to have #1043
Comments
Hey @sverrirs thanks for the issue You're totally right, so I've raised this as a bug with a chai/lib/chai/core/assertions.js Lines 1759 to 1825 in dbeae08
And here's an example of how we can do type-checking to ensure that chai/lib/chai/core/assertions.js Lines 1152 to 1165 in dbeae08
So effectively, we'll need to add the following the if (typeof name !== 'string') {
var msgPrefix = flag(this, 'message')
msgPrefix = msgPrefix ? msgPrefix + ': ' : ''
throw new AssertionError(msgPrefix + 'the argument to `property` must be a string')
} Anyone who wants to is welcome to make this PR; if you do decide you want to make this PR please add a comment below so others do not work on it at the same time! |
The value only needs to be a string if the const prop = Symbol();
expect({[prop]: 4}).to.have.property(prop); Arguably, it should accept numbers too, even though there is type coercion: expect({42: 'secret'}).to.have.property(42); |
Hey @keithamus , I would like to give a try to this. |
When calling the parsePath function (https://github.com/chaijs/chai/blob/master/chai.js#L10117) type checking can help users identify incorrect usage of API.
Problematic line:
When running this (slightly incorrect) code:
The following error is thrown:
Because path in this case is an object
{'a':'1'}
Would be nice to throw a more descriptive error :)
The text was updated successfully, but these errors were encountered: