【发布时间】:2016-05-20 04:40:24
【问题描述】:
假设我有以下React 组件:
import React from 'react'
import AppBar from 'material-ui/lib/app-bar'
class NavBar extends React.Component {
render () {
return (
<div>
<AppBar
title='My NavBar Title'
/>
</div>
)
}
}
export default NavBar
我想设置一个测试,以确保用户在呈现NavBar 时看到material-ui AppBar,为此使用Tape 和Enzyme:
import NavBar from './NavBar'
import React from 'react'
import test from 'tape'
// import { I don't know exactly what to import here. Maybe `shallow`? } from 'enzyme'
test('NavBar component test', (assert) => {
test('I should see an AppBar', (assert) => {
// How can I test for it?
// Also, can I test only for the presence of `AppBar`, without
// necessarily for the overriding of props? For example,
// even if I actually have <AppBar title='My NavBar title' />,
// can I test only for `AppBar`?
assert.end()
})
assert.end()
})
我怎样才能正确地做到这一点?
【问题讨论】:
标签: unit-testing testing reactjs enzyme