使用Jest在React组件中测试函数

时间:2015-10-13 23:33:30

标签: javascript unit-testing reactjs jasmine

我是使用React组件进行单元测试的新手。导游告诉我使用Jest,所以我跟着他们的导游。现在我遇到了这个问题,我无法对组件内的特定功能进行单元测试 如何使用Jest对函数进行单元测试,因为所有内容都被模拟(尽管我指定了dontMock

import HighFives from '../../src/components/HighFives';
import React from 'react';
import ReactTestUtils from 'react-addons-test-utils';

jest.dontMock('../../src/components/HighFives');

describe('HighFives', () => {
  it('displays the correct string', () => {
    const Component = ReactTestUtils.renderIntoDocument(<HighFives />);
    console.log(Component.makeHighfiveString());
  });
});

makeHighfiveString只是一个返回Test的测试函数,但它会返回console.log中的模拟。

0 个答案:

没有答案
相关问题