假设我有以下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
我想设置一个测试,以确保用户在渲染时看到一个material-ui AppBar ,为此使用Tape和Enzyme:NavBar
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()
})
我怎样才能正确地做到这一点?