这个测试怎么会失败?

How come this test fails?

我刚开始使用 jest 和 enzyme 进行单元测试。

我想测试组件是否有 class 名称 'comment-box'。

在我进行单元测试的组件中,我确实有一个 div 和 class 名称 'comment-box'。

但是,当我 运行 测试时,它失败了。

可能,我犯了一个容易犯的错误,因为我是笑话和酶的新手。

谁能帮我找出问题所在? 谢谢!

登录我的测试运行ner.

 FAIL  src/__tests__/components/CommentBox.test.js
  ● CommentBox › has the right class

    expect(received).toBe(expected)

    Expected value to be (using ===):
      true
    Received:
      false

CommentBox.js

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;

CommentBox.test.js

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);


    });

});

应该是

<div className="comment-box">