Can't run unit tests with Jest
See original GitHub issueWhile running a most simple unit test I get TypeError: Cannot read property 'IsAndroid' of undefined
as in issue #36 . However, building and running the app works perfectly fine.
Mocking react-native-sound
via jest.mock('react-native-sound');
doesn’t help.
The test fails in line import myComponentWithANestedSubComponentWhichUsesRNSound from './';
of the following code snippet:
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';
jest.mock('react-native-sound');
import myComponentWithANestedSubComponentWhichUsesRNSound from './';
describe('<ListItemVideo />', () => {
it('renders correctly', () => {
const tree = renderer.create(<myComponentWithANestedSubComponentWhichUsesRNSound />);
});
});
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Troubleshooting - Jest
Troubleshooting. Uh oh, something went wrong? Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why.
Read more >Jest | IntelliJ IDEA Documentation - JetBrains
You can run and debug tests with Jest right in IntelliJ IDEA. You can see the test results in a treeview and easily...
Read more >Can't run Jest tests from editor in WebStorm - Stack Overflow
I can run Jest via a run configuration and it works fine. However, I can't right-click on a test in the editor and...
Read more >Can't run unit tests with Jest #244 - GitHub
While running a most simple unit test I get TypeError: Cannot read property 'IsAndroid' of undefined as in issue #36 .
Read more >vscode-jest - Visual Studio Marketplace
tests with dynamic names (test.each with variables, template-literals, etc.) will not be translated; therefore, they can only be run through ...
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 FreeTop 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
Top GitHub Comments
If mocked it like:
and the check for function calls in my tests like
import Sound from 'react-native-sound';
…expect(Sound.prototype.play).toHaveBeenCalled();
which seems to work for me. Maybe someone else finds it useful!
Try:
jest.mock('react-native-sound', () => 'Sound')