我是Jest& amp ;;酶
我想测试该组件是否具有类名“comment-box”。
在我进行单元测试的组件中,我有一个类名为“comment-box”的div。
但是,当我进行测试时,它会失败。
可能,我犯了一个容易犯的错误,因为我是新手和开玩笑酶
有人可以帮我找出问题吗? 谢谢!
FAIL src/__tests__/components/CommentBox.test.js
● CommentBox › has the right class
expect(received).toBe(expected)
Expected value to be (using ===):
true
Received:
false
import React, { Component } from 'react';
class CommentBox extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div class="comment-box">
<textarea></textarea>
<button>Submit</button>
</div>
)
}
}
export default CommentBox;
import React, { Component } from 'react';
import { shallow, mount, render } from 'enzyme';
import CommentBox from '../../components/CommentBox';
jest.unmock('../../components/CommentBox');
describe('CommentBox', () => {
it('has the correct class', () => {
const component = shallow(<CommentBox />);
expect(component.find('div').hasClass('comment-box')).toBe(true);
// I tried this one as well.
// expect(component.find('div').first().hasClass('comment-box')).toBe(true);
});
});
答案 0 :(得分:0)
应该是
<div className="comment-box">