简体   繁体   中英

React shallow rendering - can't find text

If I console.log the wrapper.text() I can see the text '1410'. But when I test for it:

 import {shallow} from 'enzyme';
 import expect from 'expect';
 import mockery from 'mockery';

import Table from '../../../src/components/elements/_common/Table';


describe('Table', () => {

beforeEach(()=> {
    mockery.enable({
        warnOnReplace: false,
        warnOnUnregistered: false,
        useCleanCache:true
    });
});

afterEach(()=> {
    mockery.disable()
});

it('should render totals', () => {
    const TableComp= require('../../../src/component.js');
    var wrapper = shallow(<TableComp sectionData={{Total: 1410}} />);
    console.log("Output ",wrapper.text());
    expect(wrapper.text()).contains('1410').toBe(true);
});

I get:

typeError: 0 _expect2.default() contains not a function

The contains() method should be toContain() .

This is an alias of toInclude()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM