【发布时间】:2020-08-07 16:04:41
【问题描述】:
我的 react 应用程序中有一个这样的减速器。我的反应应用程序中有一个这样的减速器。我的反应应用程序中有一个这样的减速器。我的反应应用程序中有一个这样的减速器。我的反应应用程序中有一个这样的减速器。我的反应应用程序中有一个这样的减速器。我的反应应用程序中有一个这样的减速器。我的反应应用程序中有一个这样的减速器。我的 react 应用中有这样的 reducer。
reducer.ts
import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import FormField from 'wf-dbd-react-ui/es/FormField'
import FormFieldLabel from 'wf-dbd-react-ui/es/FormFieldLabel'
import FormFieldErrors from 'wf-dbd-react-ui/es/FormFieldErrors'
import Translatable from 'wf-dbd-react-ui/es/Translatable'
import Block from 'wf-dbd-react-ui/es/Block'
import withStrings from 'wf-dbd-react-ui/es/withStrings'
import { getMemoLabel } from '../../../../lib/utils/manage-payee-util'
import FormInput from 'wf-dbd-react-ui/es/FormInput'
import withMemoValidation from './withMemoValidation'
import ArialiveMemo from './ArialiveMemo'
import styles from './Memo.less'
import FormFieldErrorIcon from 'wf-dbd-react-ui/es/FormFieldErrorIcon'
import { MEMO_MAX_CHARS } from '../../../../components/workflows/edit-payment/constants'
const Memo = ({
fieldId,
defaultMemo,
memo,
isConfirm,
getString,
validateMemoField,
userTypedMemo,
isMemoFieldError,
memoFieldValidate,
defaultMemoValidate
}) => {
useEffect(() => {
memoFieldValidate(userTypedMemo <= MEMO_MAX_CHARS)
}, [userTypedMemo, memoFieldValidate] )
useEffect(() => {
defaultMemoValidate(defaultMemo && defaultMemo.length <= MEMO_MAX_CHARS)
}, [defaultMemo, defaultMemoValidate] )
const memoLabel = getMemoLabel()
return !isConfirm ? (
<Block className={styles.memo}>
<FormField fieldId={fieldId}>
<FormFieldLabel>
{ isMemoFieldError &&
<FormFieldErrorIcon className={styles.errorIcon} />
}
<div className={isMemoFieldError ? styles.errorMemoLabel : styles.memoLabel}>
<Translatable id={memoLabel} />
</div>
</FormFieldLabel>
<FormInput
className={isMemoFieldError ? styles.inputerror : styles.input}
initialValue={defaultMemo}
onChange={validateMemoField}
type="text"
maxLength={MEMO_MAX_CHARS}
placeholder={getString('memoPlaceholder')}
deleteOnUnmount={true}
/>
<FormFieldErrors />
{userTypedMemo && <ArialiveMemo count={userTypedMemo} />}
</FormField>
</Block>
) : (
<React.Fragment>
<Translatable id={memoLabel} />
<Block>
<strong className={memo.length > MEMO_MAX_CHARS ? styles.inputerror : ''}>
{memo}
</strong>
</Block>
</React.Fragment>
)
}
Memo.defaultProps = {
isConfirm: false
}
Memo.propTypes = {
fieldId: PropTypes.string,
defaultMemo: PropTypes.string,
isConfirm: PropTypes.bool,
memo: PropTypes.string,
validateMemoField: PropTypes.func,
userTypedMemo: PropTypes.number,
isMemoFieldError: PropTypes.bool,
memoFieldValidate: PropTypes.func,
defaultMemoValidate: PropTypes.func
}
export default withMemoValidation(withStrings(Memo))
但是,当我运行test-cov 时,它说第 2、3 和 8 行没有被覆盖。我如何覆盖reducer文件中的if else条件。
【问题讨论】:
标签: javascript reactjs react-redux jestjs enzyme