我正在为我的应用程序创建测试,在开玩笑地运行它们时遇到了问题。我的代码结构如下所示:
<pre>
./src/
âââ actions
â  âââ departments.js
â  âââ departments.test.js
âââ actionTypes
â  âââ departmentsTypes.js
âââ components
â  âââ common
â  â  âââ Form
â  â  â  âââ Form.css
â  â  â  âââ FormElement
â  â  â  â  âââ FormElement.css
â  â  â  â  âââ FormElement.js
â  â  â  â  âââ FormElement.test.js
â  â  â  â  âââ __snapshots__
â  â  â  âââ Form.js
â  â  â  âââ Form.test.js
â  â  â  âââ index.js
â  â  â  âââ __snapshots__
â  â  â  âââ Form.test.js.snap
â  â  âââ index.js
â  â  âââ SchemaFormFactory
â  â  â  âââ SchemaFormFactory.js
â  â  â  âââ SchemaFormFactory.test.js
â  â  â  âââ __snapshots__
â  â  â  âââ SchemaFormFactory.test.js.snap
â  â  âââ TextInput
â  âââ DepartmentSelector
â  â  âââ DepartmentSelector.css
â  â  âââ DepartmentSelector.js
â  â  âââ DepartmentSelector.test.js
â  â  âââ index.js
â  â  âââ __snapshots__
â  âââ index.js
â  âââ MainApp
â  â  âââ index.js
â  â  âââ MainApp.css
â  â  âââ MainApp.js
â  â  âââ MainApp.test.js
â  â  âââ __snapshots__
âââ containers
â  âââ DepartmentForm
â  â  âââ DepartmentForm.js
â  âââ DepartmentsSearch
â  â  âââ DepartmentsSearch.js
â  â  âââ DepartmentsSearch.test.js
â  â  âââ index.js
â  â  âââ __snapshots__
âââ helpers
â  âââ test-helper.js
âââ index.js
âââ reducers
â  âââ departments.js
â  âââ departments.test.js
</pre>
我正在尝试对FormElement(FormElement.test.js)组件进行测试。内部测试我有一个导入语句:
import DepartmentsSearch from '../../../../containers/DepartmentsSearch/DepartmentsSearch'
我的DepartmentSearch是一个容器,它使用react redux库中的connect。
import DepartmentSelector from '../../components/DepartmentSelector/DepartmentSelector'
import {createDepartment} from '../../actions'
const mapStateToProps = (state) => {
return {
departments: state.departments
}
}
export default connect(mapStateToProps, {createDepartment})(DepartmentSelector)
出于某种原因
import DepartmentSelector
import {DepartmentSelector} from '../../components'