import React, { useContext, useState } from 'react'; import { TestContext } from '../ContextProvider'; import { useDispatch } from 'react-redux'; const ExitAppButton = (props: any): JSX.Element => { const { sdkInstance } = useContext(TestContext); const exitAppClicked = () => { ...
2回答 当使用React测试库模拟上下文提供程序时,"TypeError: react.useContext不是一个函数“ 、、、 我试图确定在Jest测试时如何最好地模拟提供者。我发现最有希望的线索是RTL,它在它们的文档中提供了以下示例:玩笑测验import { render } from '@testing-library组件的简化版本,但一旦它在第2行调用useContext(...
如果我从一个新的创建-反应-应用程序开始,在测试中这样做:import { render } from '@testing-library/react然后我们可以看到,React.useContext、React.foo、lodash.drop将打印jest模拟函数,而useContext、foo和drop将打印原始对象。mo 浏览1提问于2020-08-28得票数 0 回答已采纳 2回答 在Jest中,如何仅在特定的测...
当我调用api时,模拟返回未定义的内容,然后返回正确的对象。当第一次调用api时,如果有人能帮助我,我...