This is an incomplete draft of a guide.

Components using <Trans> or withI18n() must be wrapped in <I18nProvider> in tests:

import React from 'react'
import { mount } from 'enzyme'
import { I18nProvider } from '@lingui/react'
import Component from './Component'

describe('Component', function () {
  it('should render correctly', function () {
     const tree = mount(<I18nProvider><Component /></I18nProvider>

Snapshot testing

Snapshot testing is fast and convenient way to ensure you app doesn’t change unexpectedly. However, components are serialized with all props, so even simple translation:

<Trans>Today is <DateFormat value={now} /></Trans>

has a very long and hard to read snapshot:

   I18n {
     _activeLanguageData: Object {
       plurals: [Function],
     _activeMessages: Object {},
     _catalogs: Object {
       en: Object {
         languageData: Object {},
         messages: Object {},
     _dev: Object {
       compile: [Function],
       loadLanguageData: [Function],
     _language: en,
     _locales: undefined,
     plural: [Function],
     select: [Function],
     selectOrdinal: [Function],
     t: [Function],
 id=Today is {now,date}
   Object {
     now: 2017-04-05T11:14:00.000Z,
   value=Today is 4/5/2017
   Today is 4/5/2017

In such case we might want to test just an HTML output. jest-serializer-html indents and formats HTML in snapshot making it easier to diff. Add it to Jest config:

   "snapshotSerializers": [

Instead of serializing element wrapper, serialize HTMl instead:

expect(mount(<Trans>Today is <DateFormat value={now} /></Trans>).html())

The final snapshot is shorter and easy to review:

<div>Today is 4/5/2017</div>