An alternative approach to dependency injection is monkey patching, where we dynamically modify the system at runtime. In our example, we might want to replace the create function with our stub functions, but only when we are running our tests.
Implementations of monkey patching libraries tend to be hacky and usually involves reading the module code into a string, injecting custom code into the string, and then loading it. Thus, the entities being monkey patched would be modified in some way.
There are several libraries that allow us to apply monkey patches when running tests; the most popular library is rewire (npmjs.com/package/rewire). It also has a Babel plugin equivalent called babel-plugin-rewire (github.com/speedskater/babel-plugin-rewire).
This plugin will add the __set__, __get__, and __with__ methods to every top-level file-scoped entity in the module being "rewired". Now, we can use the __set__ method of our createUser module to monkey patch our create function, like so:
createUser.__set__('create', createUserStubs.success)
The __set__ method returns a function that we can use to revert the create function back to its original state. This is useful when you want to run tests using different variants of create. In that case, you'd simply revert the create function after each test run, and patch it again at the beginning of the next run.