Open SimenB opened 4 years ago
It should be 100% doable in most cases, i have tons of npm packages to handle most of them in a cross-realm way. https://npmjs.com/~inspect-js
Oh, nice! I'm specifically after a an error check as we gave a bunch of ugly duck typing in Jest to figure out if we have an error instance or not. But I'm hesitant to add utils
usage in case it makes it harder to use parts of Jets in the browsers.
Do you have a package for Error
(i.e. util.types.isNativeError
)? Quick searching in the link you posted didn't find it, sorry if I missed something obvious. If so I'd love to use that and not worry about if it is shimmed by this package if people attempt to use e.g. expect
or something in the browser
No, unfortunately there is no JavaScript way to robustly identify a native Error - instanceof Error
is the best you can do.
https://nodejs.org/api/util.html#util_util_types
They work cross-realm (at least for
Error
coming from a newvm.Context
). Not sure if it's worth it for you to work cross-realm, but just doinginstanceof
should work OK as a shim, think?