国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 中西区| 福安市| 吴忠市| 无极县| 山东省| 旬阳县| 苗栗县| 沈丘县| 灵石县| 东辽县| 始兴县| 平潭县| 东阿县| 东港市| 马尔康县| 洪江市| 墨江| 武清区| 柳林县| 清流县| 巴青县| 宜君县| 新龙县| 阳春市| 桐城市| 荃湾区| 兰州市| 莫力| 大连市| 丰县| 寻乌县| 福州市| 凯里市| 闽侯县| 蒙自县| 若羌县| 峨眉山市| 柳河县| 游戏| 健康| 乳源|