Last active
July 27, 2021 18:44
-
-
Save marcelklehr/1c3a2fcff9166aebff728da1b4a03a5a to your computer and use it in GitHub Desktop.
mock-everything.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mock = new Proxy(() => mock, { | |
get: (target, prop) => { | |
if ( | |
prop === 'valueOf' || | |
prop === 'toString' || | |
prop === Symbol.toPrimitive | |
) { | |
return () => ''; | |
} | |
return mock | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will allow calling
mock.foo.bar.baz.blub()
while still enabling use as primitive value'' + mock.foo.bar.baz.blub === ''