question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

All seem to work fine for me, except the test fails. After installing and Linking the module, jest throws error.

 Invariant Violation: Native module cannot be null.

from the log:

at invariant (node_modules/fbjs/lib/invariant.js:42:15)
      at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:29:7)
      at Object.<anonymous> (node_modules/react-native-orientation-locker/index.js:23:25)

Need help please. Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

30reactions
rimzicicommented, Jul 24, 2018

BTW I have fixed the jest issue as you suggested, by mocking the module

jest.mock('react-native-orientation-locker', () => {
	return {
		addEventListener: jest.fn(),
		removeEventListener: jest.fn(),
		lockToPortrait: jest.fn(),
		lockToLandscapeLeft: jest.fn(),
		lockToLandscapeRight: jest.fn(),
		unlockAllOrientations: jest.fn(),
	};
});
10reactions
lfoliveir4commented, Jul 16, 2020

BTW I have fixed the jest issue as you suggested, by mocking the module

jest.mock('react-native-orientation-locker', () => {
	return {
		addEventListener: jest.fn(),
		removeEventListener: jest.fn(),
		lockToPortrait: jest.fn(),
		lockToLandscapeLeft: jest.fn(),
		lockToLandscapeRight: jest.fn(),
		unlockAllOrientations: jest.fn(),
	};
});

This solved for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

In Jest, how can I make a test fail? - Stack Overflow
Method-1. You can wrap your promise function within expect and tell jest the function should reject with the given error. If the someOperation()...
Read more >
Troubleshooting - Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​. Try using the debugging support built into...
Read more >
Jest explicitly or arbitrarily force fail() a test - Code with Hugo
Output of the test run shows that if the code doens't throw, the test suite will fail, which is desired behaviour: FAIL src/fail-throws- ......
Read more >
How to debug failing tests in jest - DEV Community ‍ ‍
Quick tip for debugging failing tests with jest. If you already know why would you want to run tests with the debugger you...
Read more >
Jest — Fail Early (And Stop Testing If One Test Fails)
Jest comes with a built-in feature to fail early if one test fails. This tutorial shows you how to configure Jest to bail...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found