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

Add a Function.constructor check to throws. #130

Merged
merged 1 commit into from
Jan 19, 2015
Merged

Add a Function.constructor check to throws. #130

merged 1 commit into from
Jan 19, 2015

Conversation

wilmoore
Copy link
Contributor

Allows you to also write:

t.throws(fn, TypeError);

@Raynos
Copy link
Collaborator

Raynos commented Dec 31, 2014

@wilmoore Please use the instanceof check as per https://github.com/joyent/node/blob/v0.10/lib/assert.js#L274

@wilmoore
Copy link
Contributor Author

@Raynos - thanks; good call. I've updated the guard to use instanceof to better match https://github.com/joyent/node/blob/v0.10/lib/assert.js#L274.

@@ -417,6 +418,11 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
expected = String(expected);
}

if (expected instanceof Function) {
passed = caught.error.constructor === expected;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caught.error instanceof expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caught.error instanceof expected

Are we 100% sure that we want to allow lose inheritance-based matching here? For example, if a TypeError is thrown, if I assert the type is Error, that would pass.

I can see cases where I'd want either of those behaviors (though, for my current use-case, I need the strict test). Perhaps we should consider a completely separate assertion for one or the other.

What do you think @Raynos?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wilmoore that's the semantics of require('assert') in node core on purpose.

Having different semantics from require('assert') is confusing and not worth it, even if they are "technically" better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having different semantics from require('assert') is confusing and not worth it...

Indeed. I agree with that. Update coming.

@Raynos
Copy link
Collaborator

Raynos commented Jan 1, 2015

lgtm :)

Raynos added a commit that referenced this pull request Jan 19, 2015
Add a Function.constructor check to throws.
@Raynos Raynos merged commit 9265529 into tape-testing:master Jan 19, 2015
@wilmoore wilmoore deleted the throws-constructor branch February 5, 2015 21:47
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

Successfully merging this pull request may close these issues.

None yet

2 participants