Enable module.exports mocking in react-test.js#156
Enable module.exports mocking in react-test.js#156benjamn wants to merge 6 commits intofacebook:masterfrom
Conversation
There was a problem hiding this comment.
Is this appropriate to commit upstream? Auto-mocking would take care of this in theory, but the details need some more work.
There was a problem hiding this comment.
This should be fine to do upstream -- it should be equivalent/redundant with automocking.
You might just add a comment so someone knows why you did it if they don't understand the redundancy
There was a problem hiding this comment.
Mocking ReactDefaultInjection will break React, since it configures a bunch of things.
There was a problem hiding this comment.
@petehunt are you saying that ReactDefaultInjection should not be auto-mocked upstream by default (as far as I know it is currently mocked automatically)?
There was a problem hiding this comment.
It is not mocked automatically. Everything in React is exempted by default. If ReactDefaultInjection were mocked React would not know anything about the browser, since it's where we inject the events system, DOM properties and tags.
|
This PR depends on #177, just to be clear. |
This is far from ideal, but it seems to be the easiest way to expose the
require.dumpCache method for use by require("mock-modules").dumpCache.
Upstream patch that would make this hack unnecessary if accepted:
browserify/browser-pack#16
We don't currently attempt to mock modules automatically, but we do
respect require("mock-modules").mock, .dontMock, and .dumpCache.
I'm going to keep investigating auto-mocking, since that would move us
much closer to the behavior used within Facebook.
Closes facebook#154.
Closes facebook#155.
The meaning of __DEV__ is pretty overloaded, so depending on that was asking for confusion.
When require("mock-modules").dumpCache() is called, all mock functions
previously created continue to refer to the old dirtyMocks array.
If we replace that array with a new one, those mock functions will never
have their .mockClear() methods called again.
The upstream version of mocks.js pulls a similar global trick, and I never
understood why until now.
|
Superseded by #193. |
We don't currently attempt to mock modules automatically, but we do respect
require("mock-modules").mock,.dontMock, and.dumpCache.I'm going to keep investigating auto-mocking, since that would move us much closer to the behavior used within Facebook.
cc @jeffmo @zpao @petehunt @tomocchino @jordwalke