我是单元测试的新手,我刚刚运行了一个测试覆盖率。这是目前唯一缺少的行。
我如何测试这条线并确保 100% 被覆盖
export default class Normalize extends Component {
constructor(props) {
super(props)
this.state = {}
// this.handleChange = this.handleChange.bind(this)
}
componentDidMount() {
this.props.normalizeData(null)
}
render () {
return (
<div id='normalize-container'>
<div id='normalize-header'>
</div>
<br /><br />
<h3 className='normalized-header'>{this.props.newResponse ? 'Raw Data' : 'Normalized Data'}</h3><br/>
<div>
{this.props.newResponse ? null :
this.props.THead ?
<div>
{!this.props.datasourceCatalog ?
<div id='next-button-modal'>
{/*<button title='Proceed To Shape' className='request-button' id='next-btn-ready-modal' onClick={this.props.nextTab}><img src={nextImg}/></button>*/}
<button title='Proceed To Shape' className='request-button' id='next-btn-ready-modal' onClick={(e) => {this.props.toggleModal(); this.props.nextTab();}}>
<FontAwesome
className='fa-angle-right'
name='view-externallink-img' …
Run Code Online (Sandbox Code Playgroud) 尝试为以下内容运行单元测试:使用 REACT JS - 这里的 Jest 和酶是代码的一部分:
componentDidMount () {
let requestSettings = this.props.getViewRequestSettings()
let linkerDefinition = requestSettings.catalog[0].resolvedtemplate[0]
if(linkerDefinition.includes('Universal')){
let functionName =
linkerDefinition.substr(0,linkerDefinition.indexOf('('));
Run Code Online (Sandbox Code Playgroud)
单元测试文件:我设置了所有道具,但不确定它是否正确
类型错误:specificMockImpl.apply 不是函数
调用道具:
// jest mock functions (mocks this.props.func)
const getViewRequestSettings = jest.fn([{requestSettings :{catalog:[0],
resolvedtemplate:[0]}}]);
// defining this.props
const baseProps = {
getViewRequestSettings,
Run Code Online (Sandbox Code Playgroud)
错误:const getViewRequestSettings = jest.fn([{requestSettings :{catalog:[0],resolutiontemplate:[0]}}]); 不确定如何正确设置
尝试获取包含 30 个 CSV 文件的 zip 文件夹的计数 测试文件夹包含 30 个 csv 文件
$directoryInfo = Get-ChildItem "$TEST\*.csv" | Measure-Object
$directoryInfo.count
Run Code Online (Sandbox Code Playgroud)
所有 30 个 csv 文件将被压缩到位于 TEST 文件夹内的 zip 文件夹 = TESTZIP1.zip 中。
如果我尝试运行以下命令来测量压缩文件夹内有多少文件,我得到 0 作为答案
$backUP = Get-ChildItem "$zipfiletest\TESTZIP1.zip\*.csv" | Measure-Object
$backUP.count
Run Code Online (Sandbox Code Playgroud)
目标:能够 Count() zip 文件夹内有多少个文件,如果 zip 文件夹与 TEST 文件夹具有相同数量的文件,则发送电子邮件。