-
-
Notifications
You must be signed in to change notification settings - Fork 700
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 for ECMA6 .to.be.a('map')
& .to.be.a('set')
#394
Comments
Would be a great idea! Our type detection is implemented in chaijs/type-detect. PR's accepted. /cc @keithamus |
Thanks for the issue @Charminbear. We can totally add these! It'd be quite simple to do so. All of our native types are listed in utils/type.js L11-19. If you'd like to extend these to add the es6 types, that'd be great! To my knowledge the new ES6 types are as follows: [object Set]
[object WeakSet]
[object Map]
[object WeakMap]
[object Symbol]
[object Promise]
[object Int8Array]
[object Uint8Array]
[object Uint8ClampedArray]
[object Int16Array]
[object Uint16Array]
[object Int32Array]
[object Uint32Array]
[object Float32Array]
[object Float64Array]
[object DataView] Of course, ES6 makes things a little more challenging because module.exports = function (obj) {
if (obj === null) return 'null';
if (obj === undefined) return 'undefined';
if (obj === Object(obj)) return 'object';
return Object.prototype.toString.call(obj).match(/^\[object (.*)\]$/)[1].toLowerCase();
}; Of course the real challenge comes with adding tests for these. I'll leave it up to your discretion how much effort to put into the tests, but there should be enough coverage to ensure new PRs don't regress the behaviour (perhaps stubbing out |
@keithamus That sounds good to me. I'm gonna have a look into it this week. Thanks a lot for the guidance already, thats already lots of thinkwork. |
We never switched over to "type-detect"? Could have sworn we did. Could we use this opportunity to do so please? |
Sorry @logicalparadox didn't notice your message! Yeah, @Charminbear if you could kindly make the pr against type-detect and also make a PR against this repo to move to type-detect that'd be just swell. Plus you'll end up on our hall of fame! |
@keithamus Yes of course, im gonna do it like this then. :) |
@keithamus @logicalparadox function getType(obj) {
var type = Object.prototype.toString.call(obj).match(/^\[object (.*)\]$/)[1].toLowerCase();
if(type === 'string' && typeof obj === 'object') return 'object'; // Let "new String('')" return 'object'
if (obj === null) return 'null'; // PhantomJS has type "DOMWindow" for null
if (obj === undefined) return 'undefined'; // PhantomJS has type "DOMWindow" for undefined
return type;
} I had to remove the As you said, the challenge was with testing: Mocha's Browser-implementation obviously doesnt like it when you Stub out I wrote some simple good-case-tests for each of the new Type you posted above. It's hard to think about other test than these when you can't even use the real Types, so I have a question: Depending, one could think to actually use the already implemented types (and I would happily do that, too). |
Hey @Charminbear, thanks for the write-up. Glad to see you're making progress. Having the catch for As for what our tests run on: https://github.com/chaijs/chai/blob/master/sauce.browsers.js is one list, plus we need to support PhantomJS & Node. So the full list:
Native support for ES6 constructors is... sporadic at best. We could test for presence and have a conditional test - but if we do I'd very much still like to see a stubbed out version that runs in every browser, so we know we're catching it. Right now, if you've got a good chunk of code then the best course of action is to set it up as a PR, and we can discuss the finer points there. |
Hey @keithamus One more thing about the second task: |
@Charminbear My thought is that native chai is the authority: |
Yup. Agree. |
Alright. Then im gonna wait until I'm done with my work on |
👍 Note that currently
results in a passing test! If Chai does not know how to compare a type, should it not throw an error so that the user knows to work around the limitation? |
Status on this? I don't see a pending PR, as alluded to above. |
@hildjj we had a PR to detect the type, and it is now available since Chai 3.0.0. @rocketraman's issue is a different issue, which should absolutely be addressed - but let's make a new issue to tackle that - this one is done. |
.to.be.a('map')
& .to.be.a('set')
@hildjj @rocketraman see chaijs/deep-eql#4. PRs welcome 😄 |
Maybe a bit off topic.. but are there any assertions for for ES6 Maps (and Sets)? For example something like:
I can use:
for now.. but that doesn't work great. |
@tiemevanveen you should raise a new issue - we can discuss the design of this and work towards adding it as a feature 😄 |
Here you go #632 :) |
Right now, when I test a variable on
to.be.a('Map')
(or 'Set'), it throws:AssertionError: expected {} to be a map
.Are you guys planning on implementing ECMA6 features?
The text was updated successfully, but these errors were encountered: