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.

Jest cannot test the component which use the RightBar

See original GitHub issue

Issue

image

code

//devSetting component

import {NavigationContext, NavigationEvent} from 'navigation-react';
import {BarButton, NavigationBar, RightBar} from 'navigation-react-native';
import React, {useContext} from 'react';
import {ScrollView, Text} from 'react-native';
import { RootNavigationTypes } from '../../../../app.types';

export const DevSettingsScreen = () => {
  const {stateNavigator} = useContext<NavigationEvent<RootNavigationTypes>>(NavigationContext);
  return (
    <>
      <NavigationBar
        title="Dev Settings"
        backTitle=""
        onNavigationPress={() => stateNavigator.navigateBack(1)}
        navigationImage={require('../../../../../assets/arrow-left.png')}>
        <RightBar>
          <BarButton title="Reset" show="ifRoom" />
        </RightBar>
      </NavigationBar>
      <ScrollView contentInsetAdjustmentBehavior="automatic">
        <Text>Dev Settings Screen</Text>
      </ScrollView>
    </>
  );
};

// test file
import 'react-native';
import React from 'react';
import {DevSettingsScreen} from './dev-settings-screen';
import {render, screen} from '@testing-library/react-native';

it('renders correctly', () => {
  render(<DevSettingsScreen />)
  expect(screen).toBeTruthy();
});


Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
anhtuank7ccommented, Nov 13, 2022

@grahammendick Sure I will. Thanks for your hard work

1reaction
grahammendickcommented, Nov 13, 2022

Hey there! I’ve finished the PR that mocks all the Navigation router components so they work with React Native Testing Library. Could you test out the mocks and let me know if you’re happy, please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest, React testing a component not exist - Stack Overflow
This is useful for asserting an element that is not present. This throws if more than one match is found (use queryAllBy instead)....
Read more >
React Testing Library Tutorial - Robin Wieruch
Learn how to use React Testing Library in this tutorial. You will learn how to test your React components step by step with...
Read more >
React Testing Library Tutorial – How to Write Unit Tests for ...
In this tutorial, you will learn how to confidently write unit tests using the Testing Library [https://testing-library.com/].
Read more >
Testing Recipes - React
Testing Recipes. Common testing patterns for React components. Note: This page assumes you're using Jest as a test runner. If you use a...
Read more >
Practically Correct, Just-in-Time Shell Script Parallelization
cant achievement even for a non-parallelizing shell—shells in widespread use differ on much larger subsets of tests. PASH-. JIT offers speedups up to...
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