我正在使用FixedDataTable (https://facebook.github.io/fixed-data-table/),我只想断言列标题的设置是正确的。以下是我的组件定义:
import React from 'react';
import {Table, Column, Cell} from 'fixed-data-table';
// Table data as a list of array.
const rows = [
['a1', 'b1', 'c1'],
['a2', 'b2', 'c2'],
['a3', 'b3', 'c3'],
// .... and more
];
// Render your table
class TestTable extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<Table
rowHeight={50}
rowsCount={rows.length}
width={900}
height={1000}
headerHeight={50}>
<Column
header={<Cell>Column 1</Cell>}
cell={<Cell>Column 1 static content</Cell>}
width={300}
/>
<Column
header={<Cell>Column 2</Cell>}
cell={<Cell>Column 2 static content</Cell>}
width={300}
/>
<Column
header={<Cell>Column 3</Cell>}
cell={({rowIndex, ...props}) => (
<Cell {...props}>
Data for column 3: {rows[rowIndex][2]}
</Cell>
)}
width={300}
/>
</Table>
);
}
}我的测试如下:
import React from 'react';
import { shallow } from 'enzyme';
import {Table, Column, Cell} from 'fixed-data-table';
import TestTable from '../../src/components/test_table';
describe('<TestTable/>', () => {
it('renders a blank table', () => {
const wrapper = shallow(<TestTable/>);
//debugger;
expect(wrapper.find(Table)).to.have.length(1);
expect(wrapper.find(Table).children()).to.have.length(3);
expect(wrapper.find(Table).childAt(0).prop('header')).to.equal(<Cell>Column 1</Cell>);
});测试失败,错误如下:
AssertionError:预期{ Object ($$typeof,type,.)}在上下文中等于{ Object ($$typeof,type,.)}。(base/test/components/test_table_test.jsx:82:83)
如何测试标头是否设置为我希望的值?如何创建针对proc的匹配程序?
我用的是酶,反应,摩卡和茶。
发布于 2016-12-15 01:09:13
您可以尝试使用酶.is选择器检查该组件是否是一个单元格,然后检查它是否收到了第1列的子支柱:
expect(wrapper.find(Table).childAt(0).prop('header').is(Cell)).to.be.true;
expect(wrapper.find(Table).childAt(0).prop('header').childAt(0)).to.equal('Column 1');.is的文档:http://airbnb.io/enzyme/docs/api/ReactWrapper/is.html
发布于 2019-03-26 13:44:33
expect(wrapper.find(Table).childAt(0).prop('header')).to.equal(<Cell>Column 1</Cell>);不工作,因为它比较对象标识,而您比较的是另一个对象。尝试使用深度相等的比较来代替:
expect(wrapper.find(Table).childAt(0).prop('header')).to.deep.equal(<Cell>Column 1</Cell>);发布于 2019-10-10 09:12:38
因为prop()返回普通对象,所以我们可以用shallow()或mount()包装它以获得包装器:
expect(
shallow(wrapper.find(Table).childAt(0).prop('header')).find(Cell).prop("children")
).to.equal("Column 1");或者使用任何其他匹配器,就像您对包装器所做的那样
https://stackoverflow.com/questions/41154539
复制相似问题