MockNativeMethods.js 1000 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. */
  9. 'use strict';
  10. const mockNativeFunction = methodName => {
  11. let warned = false;
  12. return function() {
  13. if (warned) {
  14. return;
  15. }
  16. warned = true;
  17. console.warn(
  18. 'Calling .' +
  19. methodName +
  20. '() in the test renderer environment is not supported. Instead, mock ' +
  21. 'out your components that use findNodeHandle with replacements that ' +
  22. "don't rely on the native environment.",
  23. );
  24. };
  25. };
  26. const MockNativeMethods = {
  27. measure: mockNativeFunction('measure'),
  28. measureInWindow: mockNativeFunction('measureInWindow'),
  29. measureLayout: mockNativeFunction('measureLayout'),
  30. setNativeProps: mockNativeFunction('setNativeProps'),
  31. focus: mockNativeFunction('focus'),
  32. blur: mockNativeFunction('blur'),
  33. };
  34. module.exports = MockNativeMethods;