1. /*!
    
  2.  * Copyright (c) Meta Platforms, Inc. and 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. 
    
  8. 'use strict';
    
  9. 
    
  10. const spyOn = jest.spyOn;
    
  11. 
    
  12. // Spying on console methods in production builds can mask errors.
    
  13. // This is why we added an explicit spyOnDev() helper.
    
  14. // It's too easy to accidentally use the more familiar spyOn() helper though,
    
  15. // So we disable it entirely.
    
  16. // Spying on both dev and prod will require using both spyOnDev() and spyOnProd().
    
  17. global.spyOn = function () {
    
  18.   throw new Error(
    
  19.     'Do not use spyOn(). ' +
    
  20.       'It can accidentally hide unexpected errors in production builds. ' +
    
  21.       'Use spyOnDev(), spyOnProd(), or spyOnDevAndProd() instead.'
    
  22.   );
    
  23. };
    
  24. 
    
  25. global.spyOnDev = function (...args) {
    
  26.   if (__DEV__) {
    
  27.     return spyOn(...args);
    
  28.   }
    
  29. };
    
  30. 
    
  31. global.spyOnDevAndProd = spyOn;
    
  32. 
    
  33. global.spyOnProd = function (...args) {
    
  34.   if (!__DEV__) {
    
  35.     return spyOn(...args);
    
  36.   }
    
  37. };
    
  38. 
    
  39. expect.extend({
    
  40.   ...require('../matchers/reactTestMatchers'),
    
  41.   ...require('../matchers/toThrow'),
    
  42.   ...require('../matchers/toWarnDev'),
    
  43. });