Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Testing React Native Hook with Jest

$
0
0

I've got a basic React Native app that has been barely modified and initialized using Expo:

expo init AwesomeProjectcd AwesomeProjectyarn start

The initialized app has this class:

import {  ColorSchemeName,  useColorScheme as _useColorScheme,} from "react-native";export default function useColorScheme(): NonNullable<ColorSchemeName> {  return _useColorScheme() as NonNullable<ColorSchemeName>;}

I'm going through the codebase and trying to add unit tests. I've added a few rendering tests for React Native components, but here I'm trying to unit test the useColorScheme() function. Since this is a React hook, I can't call it outside of a React function body.

// Using jestimport useColorScheme from "../useColorScheme";it('useColorScheme', () => {    const huh = useColorScheme();});

So basically my question is - What's the best way to call a React hook using jest since the hooks can only be called from a React function? (Let it be noted that I am quite new to javascript, typescript, and React)


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>