国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > WEB開發(fā) > 正文

react 單元測(cè)試,模擬操作后數(shù)據(jù)的變化

2024-04-27 15:18:14
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

參考文檔https://github.com/airbnb/enzyme/issues/341 http://www.ruanyifeng.com/blog/2016/02/react-testing-tutorial.html

1.引入enzyme 的mount 2.引入jsdom 3.調(diào)用simulate 模擬操作 4.斷言結(jié)果是否是預(yù)期

import {mount} from 'enzyme';import { expect } from 'chai';import React,{Component} from 'react';import ReactDOM from 'react-dom';import jsdom from 'jsdom'const doc = jsdom.jsdom('<!doctype html><html><body></body></html>')global.document = docglobal.window = doc.defaultViewclass App extends Component { constructor(PRops) { super(props) this.state = { count: 1 } } render() { return <h1 onClick={()=>{ this.setState({ count: this.state.count + 1 }) }}>{this.state.count}</h1> }}function shallowRender(Component) { const renderer = TestUtils.createRenderer(); renderer.render(<Component/>); return renderer.getRenderOutput();}describe('Shallow Rendering', function () { it('countTest', function () { let app = mount(<App/>); app.find('h1').simulate('click'); expect(app.find('h1').text()).to.equal('2'); });});
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平山县| 凌云县| 瑞金市| 静安区| 滕州市| 台北市| 吉林省| 襄城县| 日照市| 宁都县| 工布江达县| 宁武县| 晋城| 蓬溪县| 华容县| 南乐县| 阿图什市| 英山县| 河西区| 明溪县| 湟源县| 巩义市| 铜川市| 九寨沟县| 承德县| 繁昌县| 台前县| 黑龙江省| 枞阳县| 碌曲县| 景洪市| 象山县| 山西省| 天峻县| 伊春市| 赣州市| 兴和县| 阳原县| 乌拉特后旗| 南郑县| 会东县|