Getting TypeError: Cannot read property 'prefix' of undefined, test only
See original GitHub issueI am setting up jest in my project and get this error:
TypeError: Cannot read property 'prefix' of undefined at Object.<anonymous> (node_modules/react-native-agora/lib/src/RtcChannel.native.js:10:38) at Object.<anonymous> (node_modules/react-native-agora/lib/src/RtcEngine.native.js:3:1)
Do you have a mock available?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Cannot read property 'prefix' of undefined, test only · Issue ...
I am setting up jest in my project and get this error: TypeError: Cannot read property 'prefix' of undefined at Object.
Read more >"Cannot read property 'prefix' of undefined" when making a ...
I've been working on it for ~ a week, when suddenly I get this error: 'Cannot read property 'prefix' of undefined'.
Read more >cannot read properties of undefined (reading 'injectable')
This error occurs when you attempt to access a property on an object that is undefined. In this case, the object you are...
Read more >ERROR in Cannot read property 'length&
Can you give more information about this: ERROR in Cannot read property 'length' of undefined ? Try to update "screenfull": "^3.3.0" to latest...
Read more >Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
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
@harshaliitr I’m getting the warning
Possible Unhandled Promise Rejection: TypeError: _reactNativeAgora.default.create is not a function
. That’s triggered when I callRtcEngine.create(appId)
from my code. Have you figured out a way to mock thecreate()
function?UPDATE: I think I figured it out. I ended up going with a different solution. Instead of creating a new file that mocks
agora-react-native
, I mocked it directly injest.setup.js
. Here’s what I did:And if you don’t already have a
jest.setup.js
file, you can create a new file with that name and use it within yourjest.config.js
file like so (or in your package.json, however you configure jest should work):Solved it like this -
// create a file called
react-native-agora-mock.js
with the folllowing content - `class RtcEngine { constructor() {} }class RtcChannel { constructor() {} }
const View = require(‘react-native/Libraries/Components/View/View’);
const RtcLocalView = View const RtcRemoteView = View
export default RtcEngine; export { RtcChannel, RtcLocalView, RtcRemoteView };`
// in jest.setup.js
jest.mock('react-native-agora', () => require('./testHelpers/react-native-agora-mock'));
// in package json jest block -
"setupFiles": [ "<rootDir>/jest.setup.js", "./node_modules/react-native-gesture-handler/jestSetup.js" ]