我们如何使用酶对功能组件中的功能进行单元测试?

时间:2020-02-21 14:05:21

标签: javascript reactjs unit-testing mocha enzyme

通常使用类组件创建该组件的实例,然后可以访问该函数。我不确定如何访问功能组件的功能。

const errorMessages = {
    browse: {
        fileLimit: 'File size is too big.',
        unsupportedFormat: 'The file you selected is not a supported format. Please upload a file in .csv format.',
        noRows: 'No agent IDS could be found.',
        maxAgents: 'A max of 25 agents can be uploaded at a time.',
        noValidAgents: 'No valid agents could be found.'
    },
    duplicate: 'The following agents are already existing on the table.'
};
const UploadButton = (props, ref) => {
const mimeTypes = ['text/csv', 'application/vnd.ms-excel'];
let initialValue = false;
const [browseError, setBrowseError] = useState(initialValue);
const [uploadError, setUploadError] = useState(initialValue);
const [duplicateError, setDupplicateError] = useState(initialValue);
const [uploading, setUploading] = useState(false);
const fileInputRefs = useRef(initialValue);

const clearAllErrors = () => {
    setBrowseError(initialValue);
    setUploadError(initialValue);
    setDupplicateError(initialValue);
}
....
}

因此,例如访问clearAllErrors或errorMessages不在功能组件之外。

0 个答案:

没有答案