博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[React] Integration test a React component that consumes a Render Prop
阅读量:7062 次
发布时间:2019-06-28

本文共 1358 字,大约阅读时间需要 4 分钟。

In this lesson, I use Enzyme and Jest's Snapshot functionality to write an integration test for a component called CounterConsumer that consumes the Render Prop component Counter. This integration test is great because it doesn't necessarily care that CounterConsumer uses Counter behind the scenes, just that it works when integrated.

 

import React from "react";import Counter from "./Counter";export default function CounterConsumer({ initial }) {  return (    
{({ increment, decrement, counter }) => (

{counter}

)}
);}

 

test:

import React from "react";import ReactDOM from "react-dom";import toJSON from "enzyme-to-json";import { mount } from "enzyme";import "./enzymeSetup";import CounterConsumer from "./CounterConsumer";it("accepts an initial value", () => {  const wrapper = mount(
); expect(toJSON(wrapper)).toMatchSnapshot();});it("increments counter", () => { const wrapper = mount(
); wrapper .find("button") .at(0) .simulate("click"); expect(toJSON(wrapper)).toMatchSnapshot();});it("decrements counter", () => { const wrapper = mount(
); wrapper .find("button") .at(1) .simulate("click"); expect(toJSON(wrapper)).toMatchSnapshot();});

 

转载地址:http://ivnll.baihongyu.com/

你可能感兴趣的文章
Batch containing 11 record(s) expired due to timeout while requesting metadata
查看>>
Android Activity的生命周期
查看>>
Azure Web应用中设置静态虚拟目录的方法(比如部署Django需要用到)
查看>>
CentOS6.5配置网络
查看>>
【Linux】Ubuntu配置服务自启动 sysv-rc-conf
查看>>
oracle10g创建用户
查看>>
mybatis-入门
查看>>
oracle 11g for redhat 64
查看>>
bootstrap-徽章-链接
查看>>
bootstrap-内联文本元素-着重
查看>>
[20180312]进程管理其中的SQL Server进程占用内存远远大于SQL server内部统计出来的内存...
查看>>
LNMP相关问题——PHP无法连接MySQL之一
查看>>
WiFi Active Directory Network Policy Server Cisco WLAN Group Policy
查看>>
jetty client 与apache http client的实现、分析
查看>>
安装ubuntu14.04遇到网卡驱动不成功问题
查看>>
C语言链接mysql常用函数
查看>>
swap自动配置作业
查看>>
lsof命令的使用
查看>>
关于SQLite,SQLCipher和FMDB
查看>>
Docker--------registry私有仓库搭建 [ Http ]
查看>>