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

Document best practices for assert.expect() #1354

Closed
jzaefferer opened this issue Sep 24, 2014 · 3 comments
Closed

Document best practices for assert.expect() #1354

jzaefferer opened this issue Sep 24, 2014 · 3 comments
Assignees

Comments

@jzaefferer
Copy link
Member

Based on the discussion in #666, there are some anti-patterns around assert.expect. We should document how to use it properly, along with the anti-patterns to avoid.

Assigning this to @JamesMGreene since he had some examples for that. Along with updating http://api.qunitjs.com/expect/ we can also check other pages, like the cookbook.

@jzaefferer
Copy link
Member Author

I don't think this needs to block 1.16. I'll leave it until we get there, would certainly be good to include it.

@jzaefferer
Copy link
Member Author

Dropped the 1.16 milestone.

@Krinkle Krinkle transferred this issue from qunitjs/api.qunitjs.com Dec 29, 2018
@Krinkle Krinkle changed the title Document good usage of assert.expect Document best practices for assert.expect() Aug 24, 2020
@Krinkle
Copy link
Member

Krinkle commented Oct 14, 2023

Done at https://api.qunitjs.com/assert/expect/

This is most commonly used as assert.expect(0), which indicates that a test may pass without making any assertions. This means the test is only used to verify that the code runs to completion, without any uncaught errors. This is is essentially the inverse of assert.throws().

This can also be used to explicitly require a certain number of assertions to be recorded in a given test. If afterwards the number of assertions does not match the expected count, the test will fail.

It is recommended to test asynchronous code with assert.step() or assert.async() instead.

See also platinumazure/eslint-plugin-qunit#382

@Krinkle Krinkle closed this as completed Oct 14, 2023
@Krinkle Krinkle self-assigned this Oct 14, 2023
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