identity-obj-proxy icon indicating copy to clipboard operation
identity-obj-proxy copied to clipboard

Support Object.prototype.* calls (such as hasOwnProperty).

Open archive64 opened this issue 7 years ago • 0 comments

👋 Hi there!

We have code that looks like this:

import colors from 'colors.less';

function exampleUtilFunction(color) {
  if (!colors.hasOwnProperty(color)) {
    throw new Error();
  }
}

When using this mock, it fails with:

TypeError: colors.hasOwnProperty is not a function

As a quick fix, we added this code to the proxy:

if (key === 'hasOwnProperty') {
  return () => true;
}

I think it'd be nice if identity-obj-proxy supported the methods on Object.prototype. I'm happy to submit a PR if it would be accepted. :)

archive64 avatar Jan 09 '19 20:01 archive64