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 method for defining custom assertions #581

Closed
jzaefferer opened this issue May 30, 2014 · 4 comments
Closed

Add method for defining custom assertions #581

jzaefferer opened this issue May 30, 2014 · 4 comments

Comments

@jzaefferer
Copy link
Member

We currently suggest adding function properties to QUnit.assert, though considering the plans in #374, this might actually be a bad idea. If we make the assert argument an instance with a prototype, we may want to remove the global QUnit.assert and instead offer a method for defining custom assertions. Can be a very simple signature like this:

QUnit.addMethod( "closeEnough", function( ... ) {
  QUnit.push( ... );
});

We really need a prototype for #374 to see if that is feasible and evaluate this and some other discussions.

@leobalter
Copy link
Member

Closely related to #533

@JamesMGreene
Copy link
Member

@leobalter: Not that closely related, I'd say.

#533 is more about composing/aggregating assertions, whereas this one is simply about introducing an API abstraction for adding new assertions to the Assert prototype.

I'm not sure that this is truly necessary as we can just assume that QUnit.assert should be used as the prototype when creating a new Assert instance to pass to each test context, right?

@leobalter
Copy link
Member

Yes, and extending QUnit.assert allows the method to call this.push( condition, actual, expected, message );

@jzaefferer
Copy link
Member Author

Agreed, extending QUnit.assert still works fine, and with this.push was improved as well.

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

No branches or pull requests

3 participants