加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

unit-testing – 用酶测试react-intl组分

发布时间:2020-12-15 05:07:23 所属栏目:百科 来源:网络整理
导读:我已经查看了react-intl的建议,但它没有为 enzyme留下任何明确的文档. 这就是我试图编写测试的方法. import {IntlProvider} from 'react-intl';const intlProvider = new IntlProvider({locale: 'en'},{});const intl = intlProvider.getChildContext();cons
我已经查看了react-intl的建议,但它没有为 enzyme留下任何明确的文档.

这就是我试图编写测试的方法.

import {IntlProvider} from 'react-intl';

const intlProvider = new IntlProvider({locale: 'en'},{});
const intl = intlProvider.getChildContext();
const customMessage = shallow(<CustomMessage />,{ options: { context: intl } });

但我一直在收到错误

Invariant Violation: [React Intl] Could not find required intl object. needs to exist in the component ancestry.

我调查了他们的回购,他们似乎有made it work与’react-addons-test-utils’.

难道我做错了什么?

我已经发布了一个类似问题的答案:

Injecting react-intl object into mounted Enzyme components for testing

您可以从’intl-helper’导入{shallowWithIntl},然后使用shallowWithIntl()而不是Enzyme的shallow().

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读