Skip to content

Instantly share code, notes, and snippets.

@marcelklehr
Last active July 27, 2021 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelklehr/1c3a2fcff9166aebff728da1b4a03a5a to your computer and use it in GitHub Desktop.
Save marcelklehr/1c3a2fcff9166aebff728da1b4a03a5a to your computer and use it in GitHub Desktop.
mock-everything.js
const mock = new Proxy(() => mock, {
get: (target, prop) => {
if (
prop === 'valueOf' ||
prop === 'toString' ||
prop === Symbol.toPrimitive
) {
return () => '';
}
return mock
}
});
@marcelklehr
Copy link
Author

This will allow calling mock.foo.bar.baz.blub() while still enabling use as primitive value '' + mock.foo.bar.baz.blub === ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment