0

私は 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, ...) } が Context で { Object ($$typeof, type, ...) } と等しいと予想されます。(ベース/テスト/コンポーネント/test_table_test.jsx:82:83)

ヘッダーが希望する値に設定されていることをテストするにはどうすればよいですか? proc に対してテストするマッチャーを作成するにはどうすればよいですか?

エンザイム、リアクト、モカ、チャイを使っています。

4

3 に答える 3