AllenFang / AllenFang/react-bootstrap-table

Jest snapshot tests result in Type error

Đang mở
#1,160 4 bình luận 2 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
2.2k
Fork
761
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

First off kudos for this rather fun-to-use component :)

OK so the issue I am bumping into happens when I set up a snapshot test with Jest and react-test-renderer.

The test file is essentially:
```
import renderer from 'react-test-renderer';
import Table from '../Table';

it('matches the Table snapshot', () => {
var component = renderer.create(

);

let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
```
(Note the `Table` component is just a wrapper that defines some basic BootstrapTable props.)

And when running tests, I am alerted to this (partial stack trace):
```
TypeError: Cannot read property 'setAttribute' of null

at TableHeaderColumn.componentDidMount (../node_modules/react-bootstrap-table/lib/TableHeaderColumn.js:138:30)
at ../node_modules/react-test-renderer/lib/ReactCompositeComponent.js:265:25
```

which points back to this line in `TableHeaderColumn / ComponentDidMount`:
```
value: function componentDidMount() {
this.refs['header-col'].setAttribute('data-field', this.props.dataField);
}
```
Anyone else encounter this?

Am I doing something wrong? Apologies if should I be asking somewhere else on this; have been bouncing around Jest and React repos as well as here.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.