-
Notifications
You must be signed in to change notification settings - Fork 621
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
fix(expect): support expect.hasAssertions()
#5901
Conversation
expect.hasAssertion()
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5901 +/- ##
==========================================
- Coverage 96.31% 96.30% -0.01%
==========================================
Files 482 495 +13
Lines 39388 39571 +183
Branches 5824 5839 +15
==========================================
+ Hits 37935 38108 +173
- Misses 1411 1421 +10
Partials 42 42 ☔ View full report in Codecov by Sentry. |
testing/_bdd_utils.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file doesn't seem needed. We should just simply throw AssertionError
in testing/bdd.ts
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
expect/_assertion.ts
Outdated
|
||
const assertionState = getAssertionState(); | ||
|
||
export function hasAssertion() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function hasAssertion() { | |
export function hasAssertions() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
expect.hasAssertion()
expect.hasAssertions()
expect.hasAssertions()
expect.hasAssertions()
expect.hasAssertions()
expect.hasAssertions()
This seems only works for the first use of The below script doesn't throw with the 2nd case, which misses assertions: import { expect } from "@std/expect";
import { test } from "@std/testing/bdd";
test("1", () => {
expect.hasAssertions();
expect(1).toBe(1);
});
test("2", () => {
expect.hasAssertions();
}); |
Yes, the above code had some bugs. and I've updated. Thanks. |
testing/_test_suite.ts
Outdated
@@ -383,5 +389,11 @@ export class TestSuiteInternal<T> implements TestSuite<T> { | |||
} else { | |||
await fn.call(context, t); | |||
} | |||
|
|||
if (assertionState.checkAssertionErrorStateAndReset()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this check is unnecessary. If I removed this check, the test cases still pass.
I'm removing this block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a little tricky about this, I think you run the test inside Deno.test
and then it will never throw error. But if you remove it, then it works.
expect.hasAssertions()
expect.hasAssertions()
This API has been documented as 'still not available'. I think we can consider this addition as 'fix' as this is already expected to be added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for updating!
This pr is one of part to solve #3964, which is to support expect.hasAssertion api.