#jperf

1 messages ยท Page 1 of 1 (latest)

tranquil quartzBOT
hidden root
#
TypeError: Cannot read properties of undefined (reading 'AddressCollectionMode')
#

My current solution is the following but i am wondering if there is a more correct way...

 jest.mock('@stripe/stripe-react-native', () => ({
    ...mock,
    PlatformPayButton: jest.fn(),
    PaymentSheet: {
      AddressCollectionMode: {
        AUTOMATIC: 'automatic',
        NEVER: 'never',
        FULL: 'full',
      },
    },
    PlatformPay: {
      ButtonType: {
        Buy: 1,
      },
      BillingAddressFormat: {
        Full: 'FULL',
        Min: 'MIN',
      },
      ContactField: {
        EmailAddress: 'emailAddress',
        Name: 'name',
        PhoneNumber: 'phoneNumber',
        PhoneticName: 'phoneticName',
        PostalAddress: 'postalAddress',
      },
      PaymentType: {
        Deferred: 'Deferred',
        Immediate: 'Immediate',
        Recurring: 'Recurring',
      },
    },
  }));
prime pendant
#

let me have a look

quasi glacier
#

๐Ÿ‘‹

hidden root
#

yo

quasi glacier
#

Don't think there's a better/more correct way than what you currently have.

Looking into it though, give me a few

hidden root
#

ok

quasi glacier
#

Yeah not finding much, the mocks you currently have makes sense to me.
Is there anything in particular you're not sure about?

hidden root
#

no just wondering if there was a more elegant solution

quasi glacier
#

Gotcha. I wonder if you can directly import the enum from the types
kind of like
import {AddressCollectionMode} from '@stripe/stripe-react-native/src/types/PaymentSheet'

#

Does that make the error go away?

hidden root
#

nah that actually throws a different issues.

    Invalid variable access: AddressCollectionMode
    Allowed objects: AbortController, AbortSignal, AggregateError, Array, ArrayBuffer, Atomics, BigInt, BigInt64Array, BigUint64Array, Boolean, Buffer, DataView, Date, Error, EvalError, Event, EventTarget, FinalizationRegistry, Float32Array, Float64Array, Function, Generator, GeneratorFunction, Infinity, Int16Array, Int32Array, Int8Array, InternalError, Intl, JSON, Map, Math, MessageChannel, MessageEvent, MessagePort, NaN, Number, Object, Promise, Proxy, RangeError, ReferenceError, Reflect, RegExp, Set, SharedArrayBuffer, String, Symbol, SyntaxError, TextDecoder, TextEncoder, TypeError, URIError, URL, URLSearchParams, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray, WeakMap, WeakRef, WeakSet, WebAssembly, __dirname, __filename, arguments, atob, btoa, clearImmediate, clearInterval, clearTimeout, console, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, escape, eval, expect, exports, global, globalThis, isFinite, isNaN, jest, module, parseFloat, parseInt, performance, process, queueMicrotask, require, setImmediate, setInterval, setTimeout, undefined, unescape.
    Note: This is a precaution to guard against uninitialized mock variables. If it is ensured that the mock is required lazily, variable names prefixed with `mock` (case insensitive) are permitted.

      55 |     PlatformPayButton: jest.fn(),
      56 |     PaymentSheet: {
    > 57 |       AddressCollectionMode: AddressCollectionMode,
         |                              ^^^^^^^^^^^^^^^^^^^^^
      58 |     },
#

to be clear i am defining this within the setup.js file

#

this is probably an issue of javascript vs typescript compatiability

quasi glacier
#

I see. Yeah, was just curious.

As per my understanding, what you had before where you're mocking enums is the better approach. Mocking the enum provides more control over the values and ensures consistent behavior in your tests.

hidden root
#

gotcha ok

quasi glacier
#

Is there anything else I can help with? ๐Ÿ™‚

hidden root
#

nah thank you โค๏ธ