Can't mock library
See original GitHub issueDescribe your environment
- React-Native version: 0.57.5
- OS version: Mac OS 10.13.6 (17G65)
- react-native-languages version: 3.0.1
How to repeat issue and example
After mocking
jest.mock('react-native-languages', () => ({
RNLanguages: {
language: 'en',
languages: ['en'],
},
}))
I had this error:
TypeError: Cannot set property 'locale' of undefined
5 | I18n.locale = language
#I18n.ts
import { language } from 'react-native-languages'
import I18n from 'i18n-js'
import {ru, pl, uk, en} from './locales'
I18n.locale = language
....
export default I18n
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Can't mock library · Issue #24 · zoontek/react-native-localize
@stereodenis please tell me how to mock this library. In my jest setup file, i am having. jest.mock('react-native-languages', () => ({ RNLanguages: ...
Read more >Jest mock not working with React Testing Library
I am using @testing-library/react for testing UI components. Cannot get jest mock working. It seems it cannot mock the implementation of the ...
Read more >Manual Mocks - Jest
Manual mocks are used to stub out functionality with mock data. ... jest.mock calls cannot be hoisted to the top of the module...
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Out of the box, Mockito cannot mock final classes and final or static methods, but if you really need it, Mockito 2 provides...
Read more >How to mock a function in Jest for a React and Typescript app
import { getCharacter } from "./data"; test("Should render character name", async () => { const safe = getCharacter; // Cannot assign to ' ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can mock it like this:
@mikehardy I wrote an example in the README: https://github.com/react-native-community/react-native-localize/blob/master/README.md#how-to-test-your-code