-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
Description
When running harness tests on React Native apps using JSC (JavaScriptCore) runtime, the runtime crashes immediately with:
Object.hasOwn is not a function. (In 'Object.hasOwn(globalThis, MATCHERS_OBJECT)', 'Object.hasOwn' is undefined)
Environment
- react-native-harness: 1.0.0-alpha.20
- React Native: 0.76.x
- JS Engine: JSC (JavaScriptCore)
- Platform: iOS / Android with Hermes disabled
Root Cause
@vitest/expect v4.x uses Object.hasOwn (ES2022) which JSC doesn't support:
// @vitest/expect/dist/index.js:674
if (!Object.hasOwn(globalThis, MATCHERS_OBJECT)) {Note: This was previously misattributed to Hermes in #51, but Hermes has supported Object.hasOwn since recent versions. The issue specifically affects JSC runtime.
Proposed Solution
Add an Object.hasOwn polyfill to the runtime package that loads before @vitest/expect:
if (typeof Object.hasOwn !== 'function') {
Object.hasOwn = (obj: object, prop: PropertyKey): boolean =>
Object.prototype.hasOwnProperty.call(obj, prop);
}Workaround
Consumers can add the polyfill themselves via Metro's getPolyfills, but this should be handled in the harness since it targets React Native environments that may use JSC.
Metadata
Metadata
Assignees
Labels
No labels