alanhe421 / coding-note

note
3 stars 1 forks source link

react-intl v2升级v3 #177

Open alanhe421 opened 4 years ago

alanhe421 commented 4 years ago

tsconfig.json

    "lib": ["es2015", "es2017", "dom", "es2018.intl", "esnext.intl"],

typings.d.ts

// Extend typings
import { IntlShape } from 'react-intl';

declare global {
  interface Window {
    intl: IntlShape;
  }
}

external-files.d.ts

declare module '*.less';
declare module '*.svg';
declare module '*.png';

intl-enzyme-test-helper.tsx

import { mount } from 'enzyme';
import React from 'react';
import { IntlProvider } from 'react-intl';
import renderer from 'react-test-renderer';

const messages = {}; // en.json

export function mountWithIntl(node) {
  return mount(node, {
    // @ts-ignore
    wrappingComponent: IntlProvider,
    wrappingComponentProps: {
      locale: 'en',
      defaultLocale: 'en',
      messages
    }
  });
}

export function rendererWithIntl(node) {
  return renderer.create(<IntlProvider locale='en' messages={messages} onError={() => undefined}>{node}</IntlProvider>);
}
alanhe421 commented 4 years ago

声明文件注意细节

image