我正在使用Jest和Enzyme对使用react-transition-group
(v2.1.0)CSSTransition
的组件进行快照测试。当我创建组件的快照时,CSSTransition
会显示undefined
。这会导致React发出警告:
Warning: React.createElement: type is invalid -- expected a string
(for built-in components) or a class/function (for composite components) but got:
undefined. You likely forgot to export your component
from the file it's defined in.
这是破碎的快照差异:
- <CSSTransitionGroup
- transitionAppear={false}
- transitionEnter={true}
- transitionEnterTimeout={150}
- transitionLeave={true}
- transitionLeaveTimeout={150}
- transitionName="fade"
- />
+ <undefined
+ classNames="fade"
+ in={false}
+ mountOnEnter={true}
+ timeout={150}
+ unmountOnExit={true}
+ >
+ <div
+ className="shadow"
+ onClick={[Function]}
+ />
+ </undefined>
当我从react-transition-group v1.2.0升级到v2.1.0时,错误首次出现。这是首次导致中断出现的提交的相关部分:
-import { CSSTransitionGroup } from 'react-transition-group';
+import CSSTransition from 'react-transition-group/CSSTransition';
- <CSSTransitionGroup
- transitionName='fade'
- transitionEnterTimeout={150}
- transitionLeaveTimeout={150}
+ <CSSTransition
+ in={!!this.state.selectedCategory}
+ classNames='fade'
+ timeout={150}
+ mountOnEnter
+ unmountOnExit
>
- { this.state.selectedCategory &&
<div key='shadow' className='shadow' onClick={this.handleCancel} />
- }
- </CSSTransitionGroup>
+ </CSSTransition>
任何人都有任何想法导致这个问题吗?