Skip to content

fix: expose expect's static helpers in device specs - #85

Open
adrian-niculescu wants to merge 1 commit into
NativeScript:mainfrom
adrian-niculescu:fix/vitest-shim-expect-statics
Open

adrian-niculescu wants to merge 1 commit into
NativeScript:mainfrom
adrian-niculescu:fix/vitest-shim-expect-statics

Conversation

@adrian-niculescu

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

Copy link
Copy Markdown

In a device spec, expect.any(Number), expect.objectContaining({ ... }) and expect.extend({ ... }) throw TypeError: ... is not a function, although plain expect(value).toBe(...) works.

Device builds alias vitest to dist/runtime/shim.js, and the shim exported expect as an arrow function that forwarded each call to the device expect. Calls went through, but none of the properties setupNativeScriptExpect puts on the device expect did: the asymmetric matchers, expect.not, extend, getState and setState. The shim now exports a Proxy that forwards property reads, writes, definitions, deletions and key listing to the device expect, and refuses to be frozen, sealed or given another prototype. It still resolves the device expect on first use rather than on import, because setting it up replaces the global expect, and host tests that import from the shim (as runner.spec.ts does) would otherwise lose expect.assertions and expect.hasAssertions checks.

shim.spec.ts fails without this change, and shim-import.spec.ts fails if the shim sets up the device expect on import. I also ran a spec using these helpers through the shim on an Android 17 emulator and an iOS 26.5 simulator.

@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: 57a03d75-8160-4679-b275-8ee7cb78cfb4

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/vitest-shim-expect-statics branch 2 times, most recently from 55c2629 to c0fdfc3 Compare October 3, 2026 13:30
The vitest shim exported expect as a function that forwarded calls to
the device expect, so expect.any, expect.objectContaining, expect.not
and expect.extend were undefined in device specs. Export a Proxy that
forwards property operations to the device expect, still resolving it
on first use so importing the shim does not replace the global expect.
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