Skip to content

Instantly share code, notes, and snippets.

@ThaddeusJiang
Created November 21, 2019 12:08
Show Gist options
  • Select an option

  • Save ThaddeusJiang/51e976ea11a60afed1c2dc54f941d8fe to your computer and use it in GitHub Desktop.

Select an option

Save ThaddeusJiang/51e976ea11a60afed1c2dc54f941d8fe to your computer and use it in GitHub Desktop.
react-testing-library test Intl component

react-testing-library test Intl component

  1. install

yarn add intl --dev

  1. setup
// config/jest/setupTests.js
import '@testing-library/react/cleanup-after-each';
import IntlPolyfill from 'intl';

const setupTest = () => {
  // https://formatjs.io/guides/runtime-environments/#server
  if (global.Intl) {
    Intl.NumberFormat = IntlPolyfill.NumberFormat;
    Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
  } else {
    global.Intl = IntlPolyfill;
  }
};

setupTest();

React Intl · Testing Library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment