Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion to React Testing Library #1208

Merged
merged 42 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
56e82cb
add react-testing-library
merodiro Dec 4, 2020
337d863
migrate provider and icu tests to react testing library
merodiro Dec 4, 2020
2274b28
destructure wrapper
merodiro Dec 4, 2020
501af2a
use inline snapshots for trans.render.icu
merodiro Dec 4, 2020
e5e06a0
migrate trans.render.list to react testing library
merodiro Dec 4, 2020
bb91f14
Translation.spec.js, using toMatchInlineSnapshot, 1 test suite
tigerabrodi Dec 4, 2020
f0c7a09
Merge branch 'rtl-migration' of github.com:merodiro/react-i18next int…
tigerabrodi Dec 4, 2020
3676df2
migrate trans.render.object to react testing library
merodiro Dec 4, 2020
a075cca
Convert useTranslation.spec.js to RTL, 6 tests
tigerabrodi Dec 4, 2020
70e5c1c
Merge branch 'rtl-migration' of github.com:merodiro/react-i18next int…
tigerabrodi Dec 4, 2020
c913b06
remove empty options from render()
merodiro Dec 4, 2020
1907fb2
withTranslation.spec.js to RTL, 3 tests
tigerabrodi Dec 4, 2020
e23776c
Migrate useTranslation.ready.spec.js to RTL. 7 tests.
juhanakristian Dec 4, 2020
a28d8e0
withTranslation.spec.js: add firstChild to assertion
tigerabrodi Dec 4, 2020
717c598
Merge branch 'rtl-migration' of github.com:merodiro/react-i18next int…
tigerabrodi Dec 4, 2020
1ad16b5
remove unused enzyme import
merodiro Dec 4, 2020
e7ba58e
delete unused screen and respective comments in 3 files.
tigerabrodi Dec 4, 2020
a752a39
withSSR to RTL:
tigerabrodi Dec 4, 2020
e7835e5
Updated snapshot in withTranslation
juhanakristian Dec 5, 2020
f997669
feat: introducing @testing-library/react-hooks
balavishnuvj Dec 5, 2020
97c439e
Merge pull request #1 from merodiro/feat/introduce-testing-library-re…
tigerabrodi Dec 5, 2020
d06dac5
Use renderHook for testing useTranslation
juhanakristian Dec 6, 2020
40df72b
useTranslation.specjs to RTL, 6 tests
tigerabrodi Dec 6, 2020
3f68396
useTranslation.usedNamespaces.spec.js, 1 test
tigerabrodi Dec 6, 2020
77eb6c2
useSSR.spec.js, 1 test.
tigerabrodi Dec 6, 2020
6db81d6
Fixes test with no fallback language defined
juhanakristian Dec 6, 2020
53680ca
Added packages for the Linter setting for TL & Jest-DOM
JacobMGEvans Dec 6, 2020
6c428c7
Added extends for TL & JSDOM ESLint
JacobMGEvans Dec 6, 2020
5e30655
Based on suggestions from the issue adding the carrot in package helps
JacobMGEvans Dec 7, 2020
c9dd4aa
Cleanup of comments and unused variables
JacobMGEvans Dec 7, 2020
44fee9e
Modified an old test component that was also making assertions but wa…
JacobMGEvans Dec 7, 2020
43aab23
Removed Enzyme
JacobMGEvans Dec 7, 2020
b0bdba4
removed Div wrapper in test
JacobMGEvans Dec 7, 2020
98fe895
Merge pull request #2 from merodiro/feature/eslint-rtl-settings
JacobMGEvans Dec 7, 2020
0e4640a
Removed unused test component
juhanakristian Dec 7, 2020
664a354
add react-rest-renderer to prevent tests failing when running in runI…
tigerabrodi Dec 7, 2020
15fc415
Renamed TestElements to TestComponent
juhanakristian Dec 7, 2020
1410c4f
update test titles in useTranslation.loading.spec.js
tigerabrodi Dec 7, 2020
ced297c
Merge branch 'rtl-migration' of github.com:merodiro/react-i18next int…
tigerabrodi Dec 7, 2020
0985e09
Update test/useTranslation.loading.spec.js
JacobMGEvans Dec 7, 2020
ed26a1c
move react-test-renderer to dev dependencies
merodiro Dec 8, 2020
ff25ba1
Merge branch 'master' into rtl-migration
JacobMGEvans Dec 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@types/react": "^16.8.2",
"all-contributors-cli": "^6.1.1",
"babel-core": "^7.0.0-bridge.0",
Expand Down
19 changes: 12 additions & 7 deletions test/I18nextProvider.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { render, screen } from '@testing-library/react';
import { I18nextProvider } from '../src/I18nextProvider';
import { useTranslation } from '../src/useTranslation';

Expand All @@ -21,6 +21,7 @@ const instance = {
hasResourceBundle: (lng, ns) => ns === 'translation',
loadNamespaces: () => {},
on: () => {},
off: () => {},
options: {},
};

Expand All @@ -35,14 +36,15 @@ describe('I18nextProvider', () => {
return <div>{t('key1')}</div>;
}

const wrapper = mount(
render(
<I18nextProvider i18n={instance}>
<TestComponent />
</I18nextProvider>,
{},
);
// console.log(wrapper.debug());
expect(wrapper.contains(<div>key1</div>)).toBe(true);

// screen.debug()
expect(screen.getByText('key1')).toBeInTheDocument();
});

it('should not rerender if value is not changed', () => {
Expand All @@ -53,14 +55,17 @@ describe('I18nextProvider', () => {
return <div>{t('key1')}</div>;
});

const wrapper = mount(
const { rerender } = render(
<I18nextProvider i18n={instance}>
<TestComponent />
</I18nextProvider>,
{},
);
expect(count).toBe(1);
wrapper.setProps({ i18n: instance });
rerender(
<I18nextProvider i18n={instance}>
<TestComponent />
</I18nextProvider>,
);
expect(count).toBe(1);
});
});
12 changes: 8 additions & 4 deletions test/Translation.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { render, screen } from '@testing-library/react';
import './i18n';
import { Translation } from '../src/Translation';

Expand All @@ -11,8 +11,12 @@ describe('Translation', () => {
}

it('should render correct content', () => {
const wrapper = mount(<TestComponent />);
// console.log(wrapper.debug());
expect(wrapper.contains(<div>test</div>)).toBe(true);
const { container } = render(<TestComponent />);
// screen.debug()
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
test
</div>
`);
});
});
1 change: 1 addition & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@testing-library/jest-dom';
import configure from 'enzyme-adapter-react-helper';

configure();
88 changes: 55 additions & 33 deletions test/trans.render.icu.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { render, screen } from '@testing-library/react';
import './i18n';
import { Trans } from '../src/Trans';

Expand All @@ -8,19 +8,21 @@ describe('trans using no children but props - icu case', () => {
<Trans
defaults="hello <0>{{what}}</0>"
values={{ what: 'world' }}
components={[<strong>univers</strong>]}
components={[<strong>universe</strong>]}
/>
);
it('should render translated string', () => {
const wrapper = mount(<TestElement />);
// console.log(wrapper.debug());
expect(
wrapper.contains(
<div>
hello <strong>world</strong>
</div>,
),
).toBe(true);
const { container } = render(<TestElement />);
// screen.debug()

expect(container.firstChild).toMatchInlineSnapshot(`
<div>
hello
<strong>
world
</strong>
</div>
`);
});
});

Expand All @@ -38,15 +40,18 @@ describe('trans using no children but props - nested case', () => {
/>
);
it('should render translated string', () => {
const wrapper = mount(<TestElement />);
// console.log(wrapper.debug());
expect(
wrapper.contains(
const { container } = render(<TestElement />);
// screen.debug()

expect(container.firstChild).toMatchInlineSnapshot(`
<div>
<span>
hello <br /> world
</span>,
),
).toBe(true);
hello
<br />
world
</span>
</div>
`);
});
});

Expand All @@ -55,16 +60,15 @@ describe('trans using no children but props - self closing case', () => {
<Trans defaults="hello <0/>{{what}}" values={{ what: 'world' }} components={[<br />]} />
);
it('should render translated string', () => {
const wrapper = mount(<TestElement />);
// console.log(wrapper.debug());
expect(
wrapper.contains(
<div>
hello <br />
world
</div>,
),
).toBe(true);
const { container } = render(<TestElement />);
// screen.debug()
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
hello
<br />
world
</div>
`);
});
});

Expand All @@ -80,8 +84,17 @@ describe('Trans should use value from translation', () => {
/>
);

const wrapper = mount(<TestElement />);
expect(wrapper.contains(<span className="awesome-styles">dragonfly</span>)).toBe(true);
const { container } = render(<TestElement />);
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
Result should be rendered within tag
<span
class="awesome-styles"
>
dragonfly
</span>
</div>
`);
});

it('should use value from translation if dummy data provided in component', () => {
Expand All @@ -95,7 +108,16 @@ describe('Trans should use value from translation', () => {
/>
);

const wrapper = mount(<TestElement />);
expect(wrapper.contains(<span className="awesome-styles">dragonfly</span>)).toBe(true);
const { container } = render(<TestElement />);
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
Result should be rendered within tag
<span
class="awesome-styles"
>
dragonfly
</span>
</div>
`);
});
});
44 changes: 27 additions & 17 deletions test/trans.render.list.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount } from 'enzyme';
import { render } from '@testing-library/react';
import './i18n';
import { Trans } from '../src/Trans';

Expand All @@ -19,16 +19,21 @@ describe('Trans should render nested components', () => {
]}
/>
);
const wrapper = mount(<TestElement />);
const { container } = render(<TestElement />);

expect(
wrapper.contains(
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
Result should be a list:
<ul>
<li>li1</li>
<li>li2</li>
</ul>,
),
).toBe(true);
<li>
li1
</li>
<li>
li2
</li>
</ul>
</div>
`);
});

it('should render dynamic ul as components property when pass as a children', () => {
Expand All @@ -44,14 +49,19 @@ describe('Trans should render nested components', () => {
</ul>
</Trans>
);
const wrapper = mount(<TestElement />);
expect(
wrapper.contains(
const { container } = render(<TestElement />);
expect(container.firstChild).toMatchInlineSnapshot(`
<div>
Result should be a list:
<ul>
<li>li1</li>
<li>li2</li>
</ul>,
),
).toBe(true);
<li>
li1
</li>
<li>
li2
</li>
</ul>
</div>
`);
});
});
Loading