1

我正在使用ReactJS和迈出第一步Jest

下面的期望通过,即使它不应该。查看属性如何打印:

console.log(searchBox.props.url_variation); 
// prints: curation/get_site_variations/

那么为什么期望没有失败呢?

jest.dontMock('../databank_web/static/js/curation_tools/SearchBox.js');

describe('SearchBox', function () {
    it('loads results after click', function () {
        var React = require('react/addons');
        var TestUtils = React.addons.TestUtils;
        var SearchBox = require('../databank_web/static/js/curation_tools/SearchBox.js');

        // Render the form?
        var searchBox = TestUtils.renderIntoDocument(<SearchBox
            url_variation="curation/get_site_variations/"
            url_golden="curation/golden_record/"/>);


        console.log(searchBox.props.url_variation); // prints: curation/get_site_variations/

        expect(searchBox.props.url_variation === "fail");
// Why is this passing? fail is not equal to 'curation/get_site_variations/'

    });
});
4

1 回答 1

0

将您的期望更改为以下内容:

expect(searchBox.props.url_variation).toEqual("fail")

这将导致测试失败。它通过的原因是expect(false)不会导致测试失败。我相信这种行为实际上是从 Jasmine 那里继承来的,期望本身就是价值。链式匹配器是导致测试通过或失败的原因。

于 2015-02-03T15:01:38.780 回答