Skip to content

fix: support expect.assertions and the other missing expect helpers on device - #86

Open
adrian-niculescu wants to merge 1 commit into
NativeScript:mainfrom
adrian-niculescu:fix/device-expect-assertion-checks
Open

adrian-niculescu wants to merge 1 commit into
NativeScript:mainfrom
adrian-niculescu:fix/device-expect-assertion-checks

Conversation

@adrian-niculescu

@adrian-niculescu adrian-niculescu commented Oct 3, 2026 •

Copy link
Copy Markdown

Depends on #85: specs import expect from vitest, which resolves to the runtime shim, and only with #85 does the shim's expect pass its properties through to the device expect. Until then the new methods are reachable on the global and the context expect only.

In a device spec, expect.assertions(n), expect.hasAssertions(), expect.soft(), expect.unreachable() (which the Karma migration guide suggests in place of Jasmine's fail()), expect.assert, expect.addEqualityTesters() and the toSatisfy and toBeOneOf matchers throw ... is not a function. The test context has no expect, the expect.requireAssertions option has no effect, and a test that forgets to await a failing .resolves or .rejects assertion passes.

setupNativeScriptExpect builds the device expect from Chai's, but leaves out what Vitest's createExpect adds on top of it, including binding each assertion to its test, which is how the runner awaits forgotten async assertions and records soft failures. It already counts assertions, but the device runner never resets that count per test or compares it with what the test asked for, which Vitest's runner does in onBeforeTryTask and onAfterTryTask. The device expect now gets the same methods, matchers and binding, and each test gets an expect on its context with its own assertion count. The device runner resets the global count before each test attempt and checks the count after it, with Vitest's error messages and its requireAssertions option. As in Vitest, a test that uses its context's expect is checked against that expect alone, so concurrent tests do not count each other's assertions.

expect.poll is still missing.

The new cases in expect.spec.ts and runner.spec.ts fail without this change. I also ran a spec using all of these, including concurrent tests and aroundEach with the context expect, with #85 applied, on an Android 17 emulator and an iOS 26.5 simulator, and requireAssertions on the emulator.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 93c7f860-97ab-4d3e-b8df-ab7ef309c695

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@adrian-niculescu
adrian-niculescu force-pushed the fix/device-expect-assertion-checks branch 3 times, most recently from d47f2da to 58ce4ff Compare October 3, 2026 15:07
…n device

The device expect lacked what Vitest's createExpect adds to Chai's
expect: assertions, hasAssertions, soft, unreachable, assert,
addEqualityTesters, the toSatisfy and toBeOneOf matchers, and binding
each assertion to its test. Tests had no context expect, and the device
runner never reset or checked the assertion count per test. Add them,
and reset and check the count around each test attempt, honouring
expect.requireAssertions.
@adrian-niculescu
adrian-niculescu force-pushed the fix/device-expect-assertion-checks branch from 58ce4ff to ed1b06d Compare October 3, 2026 15:17
@adrian-niculescu
adrian-niculescu marked this pull request as ready for review October 3, 2026 17: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.

1 participant