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

instanceOf() #8

Closed
Qix- opened this issue Aug 29, 2015 · 10 comments
Closed

instanceOf() #8

Qix- opened this issue Aug 29, 2015 · 10 comments

Comments

@Qix-
Copy link

Qix- commented Aug 29, 2015

Need instanceOf()!

@sindresorhus
Copy link
Contributor

I honestly never use instanceof. What do you use it for?

We might pass on this unless there's strong opinions otherwise as we're trying to keep this module small and focused. Can always use heavier assertion libs if you need something like this. Keeping it open for discussion though.

@arthurvr
Copy link
Collaborator

Yeah, me neighter. I practically never use it.

@tunnckoCore
Copy link

Yeah, me neighter. I practically never use it.

👍 Only place i use it is assert.throws(fn, TypeError) + assert.throws(fn, msg) combo.

@Qix-
Copy link
Author

Qix- commented Aug 30, 2015

async.each([1, 2, 3], function (cb) {
  claim.instanceOf(cb, Function); // make sure async is correctly passing me a function callback
});

Obviously I'm not writing tests for async, but I over-test my frameworks to make sure they're giving me exactly what I'm expecting.

@tunnckoCore
Copy link

why not?

async.each([1, 2, 3], function (cb) {
  claim.is(cb instanceof Function, true); // make sure async is correctly passing me a function callback
});

@Qix-
Copy link
Author

Qix- commented Aug 30, 2015

For the same reason

claim.is(1, 1);

instead of

claim.true(1 === 1)

@sindresorhus
Copy link
Contributor

@Qix-

claim.instanceOf(cb, Function);claim.is(typeof cb, 'function');

You shouldn't use instanceof with Function as it won't work if it comes from another realm like windows/frames in the browser. And with typeof, you can just use .is().

@Qix-
Copy link
Author

Qix- commented Aug 30, 2015

@sindresorhus I understand, though in Node in particular that isn't a problem. If I need to check instanceof for anything, not even Functions in particular, then I have to use instanceof. claim could even do

claim.instanceOf(obj, SomeFunction); // obj.constructor.name === SomeFunction.name

Using .is() defeats the purpose of a library re-creating these methods for better error output, right?

@sindresorhus
Copy link
Contributor

Seeing as this is IMHO and obscure case, I'd prefer we go with power-assert on this one.

claim.ok(obj instanceOf SomeFunction);

avajs/ava#46

@Qix-
Copy link
Author

Qix- commented Sep 19, 2015

Agreed with that.

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

No branches or pull requests

4 participants