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.

Native Base <Content/> type is not rendered

See original GitHub issue

Hi, I have this component:

import {
	Container,
	Content,
	Text,
} from 'native-base';


<Container style={styles.container}>			
	<Content padder>
		<Text testID={'emptyCasesList'}>Cases list is empty</Text>
	</Content>
</Container>

But the test can’t find the ‘emptyCasesList’ element. when I run debug.deep, I can’t see the <Content/> element nor the <Text>. BUT - when I remove the <Content/> element (leaving just the <Text/>), test passes and I see the <Text/> element. If the answer is something like “NativeBase is mocking the <Content/> in tests” - could you please elaborate further?

Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
thymikeecommented, Jun 4, 2019

Hey! I looked into the example and it indeed doesn’t work. So I jumped into native-base internals and found this: https://github.com/GeekyAnts/NativeBase/blob/65f0bc7ff53b28099d177813d2b33ffd987cadcd/src/basic/Content.js#L90-L95

The Content component uses react-native-keyboard-aware-scroll-view under the hood, which is just not mocked properly. I can see it’s even named KeyboardAwareScrollViewMock, not sure where it comes from (maybe jest-expo? I’ll leave that to you to investigate).

Here’s the diff that fixes your tests (of course this mock is very basic, feel free to make it closer to the original and send a PR to the library maintainers, or use a better one if available already):

diff --git a/App.test.js b/App.test.js
index 08bb08d..c02713e 100644
--- a/App.test.js
+++ b/App.test.js
@@ -4,6 +4,10 @@ import {
     Content, Container, Text
 } from 'native-base';

+jest.mock('react-native-keyboard-aware-scroll-view', () => {
+    const KeyboardAwareScrollView = ({ children }) => children;
+    return { KeyboardAwareScrollView };
+});

 class App extends React.Component {

@@ -34,4 +38,4 @@ describe('Testing Content', () => {
         expect(queryByTestId('textIdInside')).not.toBeNull()
     });

-})
\ No newline at end of file
+})

Closing, as that’s not an issue with this library, but with mocking in general.

0reactions
pedrohbtpcommented, Jun 3, 2019

@thymikee , thank you for the reply and I apologize for the misunderstanding.

I created the following repository to reproduce the behavior: https://github.com/pedrohbtp/rntl-content-bug

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content Component in Native Base React is not rendering
I desigining react native UI using Native base library(http://docs.nativebase.io/Components.html#anatomy-headref). I am following their most ...
Read more >
Components
This is a NativeBase component which renders as body element of your screen. Each screen can have only one Content component and can...
Read more >
native-base
native -base. TypeScript icon, indicating that this package has built-in type declarations · Readme · Code Beta · 34 Dependencies · 288 Dependents ......
Read more >
Components · Native Base Docs - Remicck
NativeBase component that renders as footer, include your favourite apps for your ... Content, Badge, Text, Icon } from 'native-base'; export default class...
Read more >
How to use the native-base.Picker.Item function in ...
Platform, } from 'react-native'; import { Container, Button, Icon, Text, Header, Title, Content, Left, Body, Right, Form, Label, Input, Picker, Switch, Item as ......
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