原创 ts+react 單元測試 測react-route

組件如下 import {Link, Route, Switch, Redirect, withRouter, RouteComponentProps} from "react-router-dom"; /** path of rou

原创 ts+react路由react-router-dom

記錄自己項目中寫的內容 路由入口是一個組件, 路由出口用Switch包着,大概如下 <TopNavigationBarWithRoute routePath={this.state.routePath

原创 如何在項目中配置tslint

1.2.1 先打開VSCODE編輯器的tslint 1.2.2 在全局下載tslint npm install -g tslint typescript 1.2.3 初始化tslint(生成tslint.json文件) tslint

原创 在react中使用mocha和chai以及enzyme

採用creat-react-app腳手架和mocha和chai以及enzyme 使用mocha和chai 做法 怎麼在組件裏面用呢(mocha+chai+enzyme) 展示部分 我們來看做法 參考 使用mocha和chai 做法 1:新

原创 ts+tslint+react背景下寫select的onChange事件

 如何調用呢?這麼寫可行 <select value={this.state.limit} onChange={this.handleLimit} >

原创 在測試文件tsx中import React from "react"報錯

原因 尚未找到(猜測是ts+react默認沒有配置TSX識別文件,需要下載) 解決方案 下載ts-node並在mocha.opts中配置 npm i -D ts-node (參考下面這位大佬的文章) https://blog.csdn.n

原创 如何用mocha找到子組件的className

Question 如何用mocha找到子組件的className 解決方案 父組件.find(子組件名.shallow()   const frame = shallow( <Gallery loggerFa

原创 ts+react, 用mocha測試setInterval,

Question 如何用mocha測試setInterval, 在代碼中,將setInterval和clearInterval放在一個函數中,並且用一個公共屬性public或private屬性來賦值,測試的時候會報錯   原因 mocha

原创 react中使用enzyme.mount和sinon

我在網上搜了很多,但是沒找到符合我項目場景使用的,自我摸索出能用的一個小案例,可能有不太對的地方,請見諒,僅做一個記錄:  注意哦,這個主要來測componentDidmount和componentWillUnmount。 我的項目是re

原创 自定義組件下拉搜索選擇框

最終效果:   代碼如下 interface export interface IFilter { /** unique id */ id: string; /** machine serial number

原创 用mocha測試select

Question 如何用mocha測試select 原因 尚未找到 解決方案 使用event和simulate結合      const event = { target: { value: 25 }

原创 react+ts實現點擊按鈕下載圖片,兼容IE

(適用於react+ts) 第一種 <FontAwesomeIcon  icon={faDownload} onClick={() => this.downloadCurrentImage()} className="ImageFra

原创 axios API

**API**(僅作記錄) // axios import axios from "axios"; // content-type axios.defaults.headers.post["Content-Type"] = "appli

原创 setTimeout寫輪詢

 代碼如下(每個幾秒發送請求,刷新數據) private startTimer(autoRefreshTimeS: number) { if (autoRefreshTimeS < 0) { this.stopT

原创 如何用mocha找到子組件的prop state

Question 如何用mocha找到子組件的prop  state 解決方案 父組件.find(子組件名).props().XXX     父組件.find(子組件名).prop( XXX  )   父組件.find(子組件名).sta