Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change jest native method mocks to jest functions (#24337)
Summary: Currently calling native methods on internal react native components throw a warning. I believe this is problematic because _users_ aren't calling native methods on internal components, the _component_ is making the call. So for instance, if I unmount a component that has a form with a few uses of `TextInput`, which is a perfectly valid test case, my test output will be full of warnings that I can't call `.blur()` in the test renderer environment. That's very misleading, because I didn't, the internal component did. In fact, as far as I can tell, there's not really even anything I can do to stop that call or use the output from it, its all internal. `TextInput` is a black box, and 99% of users writing tests probably won't even know it calls `.blur()` under the hood on unmount. I want to change these to `jest.fn()` because I think this eliminates a lot of chatter in test output, but also doesn't send users down a rabbit hole of trying to find workarounds that may involve filtering console output, which could potentially lead them to inadvertently filter out real warnings that they should see. So I'm willing to change the implementation of how I did this, but I don't think its right to warn users that they called a native method when they didn't. If they build a component that calls these methods, I believe it's on them to do something similar to this, and maybe we can make this exposed as a helper that can be used for third party component mocks? [General] [Changes] - Changed MockNativeMethods for core components to `jest.fn()` instead of function that warns about calling native methods. Pull Request resolved: #24337 Differential Revision: D14822126 Pulled By: cpojer fbshipit-source-id: 2199b8c8da8e289d38823bdcd2c43c82f3f635c9
- Loading branch information