道具类型失败:提供给“组件”的“对象”类型的道具“ iconBack”无效,测试文件中的预期“数量”

时间:2018-07-02 09:32:14

标签: unit-testing react-native jestjs

我测试一个组件包含一个具有Image的子组件。我在子组件中定义Image的propTypes为number。在主要组件上,我通过了import的图像道具。但是测试文件运行警告提供给iconBack的类型object的道具HeaderVideoNavigation无效HeaderVideoNavigation

enter image description here

这是const HeaderVideoNavigation = props => ( <Container> <IconContent> <TouchableWithoutFeedback onPress={props.onPressBackIcon}> <IconButton isDisplay source={props.iconBack} /> </TouchableWithoutFeedback> </IconContent> {!!props.editText && <EditText>{props.editText}</EditText>} </Container> ) 上的代码

<Header>
  <HeaderVideoNavigation
    onPressBackIcon={closeModal}
    iconBack={Images.iconBackWhite}
  />
</Header>

和主要组件

  $files= scandir($dir);
  $zip = new ZipArchive();


  $tmp_file = tempnam('.','');
  if (  $zip->open($tmp_file, ZipArchive::CREATE)===TRUE) {
    # loop through each file
    foreach($files as $file){

        # download file
        $download_file = file_get_contents($file);

        #add it to the zip
        $zip->addFromString(basename($file),$download_file);

    }

    # close zip
    $zip->close();

    # send the file to the browser as a download
    header("Content-disposition: attachment; filename=$nome_dir.zip");
    header("Content-length: " . filesize($tmp_file));
    header('Content-type: application/zip');
    readfile($tmp_file);
  }

1 个答案:

答案 0 :(得分:0)

警告基本上说iconBackWhite是一个对象,而不是其源属性的IconButton组件中期望的数字。

<IconButton isDisplay source={props.iconBack} />