我无法找到我渲染的DashBoard组件。我正在使用酶的mount()。
我在安装后得到一个返回的实例,所以不确定我如何找到()我的组件,因为它不能识别包装上的find()
jsdom.js
const jsdom = require('jsdom')
const { JSDOM } = jsdom
global.window = new JSDOM(`<!doctype html><html><body id='root'></body></html>`).window
global.document = window.document
测试
require('../jsdom')
describe('Protected Route', () => {
let store, app, index, responseBody
beforeEach(() => {
store = initStore()
const App = ({store}) => (
<Provider store={store}>
<Layout>
<Switch>
<ProtectedRoute component={DashboardContainer} path='/dashboard'/>
</Switch>
</Layout>
</Provider>)
app = mount(<MemoryRouter><App store={store} /></MemoryRouter>)
})
it.only('renders requested route if authenticated', () => {
const dashboard = app.find(DashboardContainer)
expect(dashboard).to.exist
})
})
问题是app指的是实例。它尝试了app.dive(),但它没有识别潜水()。 app.find()给TypeError: Cannot read property 'find' of undefined