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.

Cannot read property 'style' of undefined

See original GitHub issue

I get this error when I run my tests with jest and it tries to import react-native-snap-carousel : TypeError: Cannot read property 'style' of undefined at Object.<anonymous> (node_modules/react-native-snap-carousel/index.js:472:842)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
thurtcommented, Apr 13, 2017

hi guys,

ran into this problem as well.

i think the problem is related to these three lines https://github.com/archriss/react-native-snap-carousel/blob/master/index.js#L56 https://github.com/archriss/react-native-snap-carousel/blob/master/index.js#L60 https://github.com/archriss/react-native-snap-carousel/blob/master/index.js#L87

if I temporarily comment those lines out in node_modules/react-native-snap-carousel then jest test no longer gets the described error.

these three lines appear to point to this line in react-native source -> https://github.com/facebook/react-native/blob/v0.43.1/Libraries/Components/ScrollView/ScrollView.js#L297

a temporary solution is to create a mock react-native-snap-carousel.js inside a __mocks__ folder. mine just looks like:

/*
  FIXME: using an empty mock in order to bypass jest test error. see tracking issue: https://github.com/archriss/react-native-snap-carousel/issues/43
 */
module.exports = () => {};
1reaction
nicolas-amabilecommented, Feb 28, 2020

I recently had a similar issue while running some tests Screen Shot 2020-02-28 at 19 32 01

Since I need to make assertions on each carousel item, I implemented this simple mock:

// __mocks__/react-native-snap-carousel/index.js
const Carousel = ({ data, renderItem }) => data.map((item) => renderItem({ item }));
export default Carousel;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'style' of undefined -- Uncaught Type Error
1. This works when I try it here: jsfiddle.net/du2ot93e - I think your if statement is failing. · Do you reach the if...
Read more >
How To Fix Cannot Read Property 'style' of Null in JavaScript
This error boils down to one problem. The element you are trying to access does not exist in the DOM (document object model)...
Read more >
Cannot read property 'style' of undefined" browser console error
Symptoms. Form is in a broken state (example - right click menu options, related lists, reference fields etc are unavailable) as a result...
Read more >
Cannot read property 'style' of undefined · Issue #779 - GitHub
Works fine on android device. TypeError: Cannot read property 'style' of undefined. Module.../../../react-native-snap- ...
Read more >
Cannot read property 'style' of undefined on Details Row
Cannot read property 'style' of undefined on Details Row ... I have a details row with datatables. Details row is working properly, but...
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