Skip to content

Instantly share code, notes, and snippets.

@quantizor
Last active October 17, 2016 16:33
Show Gist options
  • Save quantizor/3b72f058215cda56b4055531e1f69c03 to your computer and use it in GitHub Desktop.
Save quantizor/3b72f058215cda56b4055531e1f69c03 to your computer and use it in GitHub Desktop.
react-redux connect() mock for Jest
/*
place this somewhere above where your test files are in a directory called __mocks__, e.g.
__mocks__/
react-redux.js
src/
myTestFile.spec.js
Requires an updated version of node with ES6 Proxy support.
*/
const proxiedObject = new Proxy({}, {
get: function alwaysReturnSomething(target, name) { return name in target ? target[name] : proxiedObject; },
});
module.exports = {
connect: (cb = () => {}) => {
cb(proxiedObject);
return (x) => x;
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment