Repository navigation
fix: expose expect's static helpers in device specs - #85
Open
adrian-niculescu wants to merge 1 commit into
Open
adrian-niculescu wants to merge 1 commit into
adrian-niculescu wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
adrian-niculescu
force-pushed
the
fix/vitest-shim-expect-statics
branch
2 times, most recently
from
October 3, 2026 13:30
55c2629 to
c0fdfc3
Compare
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.
adrian-niculescu
force-pushed
the
fix/vitest-shim-expect-statics
branch
from
October 3, 2026 13:38
c0fdfc3 to
ab88519
Compare
adrian-niculescu
marked this pull request as ready for review
October 3, 2026 14:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a device spec,
expect.any(Number),expect.objectContaining({ ... })andexpect.extend({ ... })throwTypeError: ... is not a function, although plainexpect(value).toBe(...)works.Device builds alias
vitesttodist/runtime/shim.js, and the shim exportedexpectas an arrow function that forwarded each call to the deviceexpect. Calls went through, but none of the propertiessetupNativeScriptExpectputs on the deviceexpectdid: the asymmetric matchers,expect.not,extend,getStateandsetState. The shim now exports a Proxy that forwards property reads, writes, definitions, deletions and key listing to the deviceexpect, and refuses to be frozen, sealed or given another prototype. It still resolves the deviceexpecton first use rather than on import, because setting it up replaces the global expect, and host tests that import from the shim (asrunner.spec.tsdoes) would otherwise loseexpect.assertionsandexpect.hasAssertionschecks.shim.spec.tsfails without this change, andshim-import.spec.tsfails if the shim sets up the deviceexpecton import. I also ran a spec using these helpers through the shim on an Android 17 emulator and an iOS 26.5 simulator.