Move react-i18next mock to jest-setup.js

This commit is contained in:
MariaZ
2022-09-20 12:37:41 +02:00
parent 82b6a6b603
commit 726b65914b
6 changed files with 4 additions and 44 deletions
+1 -8
View File
@@ -1,5 +1,6 @@
import React from 'react' import React from 'react'
import { render, screen, fireEvent } from '@testing-library/react-native' import { render, screen, fireEvent } from '@testing-library/react-native'
import AcceptLicense from '../../components/AcceptLicense' import AcceptLicense from '../../components/AcceptLicense'
import { saveLicenseFlag } from '../../local-storage' import { saveLicenseFlag } from '../../local-storage'
@@ -8,14 +9,6 @@ jest.mock('../../local-storage', () => ({
saveLicenseFlag: jest.fn(() => Promise.resolve()), saveLicenseFlag: jest.fn(() => Promise.resolve()),
})) }))
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (str, options) => {
return str + (options ? JSON.stringify(options) : '')
},
}),
}))
describe('AcceptLicense', () => { describe('AcceptLicense', () => {
test('On clicking OK button, the license is accepted', async () => { test('On clicking OK button, the license is accepted', async () => {
const mockedSetLicense = jest.fn() const mockedSetLicense = jest.fn()
+1 -8
View File
@@ -1,14 +1,7 @@
import React from 'react' import React from 'react'
import { render } from '@testing-library/react-native' import { render } from '@testing-library/react-native'
import AppHelp from '../../../components/common/AppHelp'
jest.mock('react-i18next', () => ({ import AppHelp from '../../../components/common/AppHelp'
useTranslation: () => ({
t: (str, options) => {
return str + (options ? JSON.stringify(options) : '')
},
}),
}))
describe('AppHelp screen', () => { describe('AppHelp screen', () => {
test('when provided text, should render it', async () => { test('when provided text, should render it', async () => {
+1 -8
View File
@@ -1,14 +1,7 @@
import React from 'react' import React from 'react'
import { render } from '@testing-library/react-native' import { render } from '@testing-library/react-native'
import StatsOverview from '../../../components/common/StatsOverview'
jest.mock('react-i18next', () => ({ import StatsOverview from '../../../components/common/StatsOverview'
useTranslation: () => ({
t: (str, options) => {
return str + (options ? JSON.stringify(options) : '')
},
}),
}))
describe('StatsOverview screen', () => { describe('StatsOverview screen', () => {
test('when provided correct, renders it', async () => { test('when provided correct, renders it', async () => {
@@ -3,12 +3,6 @@ import { render } from '@testing-library/react-native'
import StatsTable from '../../../components/common/StatsTable' import StatsTable from '../../../components/common/StatsTable'
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (str, options) => str + (options ? JSON.stringify(options) : ''),
}),
}))
const mockGetStats = jest const mockGetStats = jest
.fn() .fn()
.mockImplementationOnce(() => [ .mockImplementationOnce(() => [
+1 -8
View File
@@ -1,14 +1,7 @@
import React from 'react' import React from 'react'
import { render, screen } from '@testing-library/react-native' import { render, screen } from '@testing-library/react-native'
import License from '../../../components/settings/License'
jest.mock('react-i18next', () => ({ import License from '../../../components/settings/License'
useTranslation: () => ({
t: (str, options) => {
return str + (options ? JSON.stringify(options) : '')
},
}),
}))
describe('License screen', () => { describe('License screen', () => {
test('It should have a correct year', async () => { test('It should have a correct year', async () => {
-6
View File
@@ -8,12 +8,6 @@ jest.mock('../../components/common/StatsOverview', () => 'StatsOverview')
jest.mock('../../components/common/StatsTable', () => 'StatsTable') jest.mock('../../components/common/StatsTable', () => 'StatsTable')
jest.mock('../../assets/cycle-icon.png', () => 'image') jest.mock('../../assets/cycle-icon.png', () => 'image')
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: (str, options) => str + (options ? JSON.stringify(options) : ''),
}),
}))
const mockGetAllCycleLengths = jest const mockGetAllCycleLengths = jest
.fn() .fn()
.mockImplementationOnce(() => []) .mockImplementationOnce(() => [])