我有一个来自 API 文档的非常简单的AsyncTypeahead示例:
import {AsyncTypeahead} from "react-bootstrap-typeahead";
import React, {Component} from "react";
class AsyncTest extends Component<Props, State> {
constructor() {
super()
this.state = {
isLoading:false,
options:{}
}
}
render() {
return <AsyncTypeahead
disabled={true}
isLoading={this.state.isLoading}
onSearch={query => {
this.setState({isLoading: true});
fetch(`https://api.github.com/search/users?q=123`)
.then(resp => resp.json())
.then(json => this.setState({
isLoading: false,
options: json.items,
}));
}}
options={this.state.options}
/>
}
}
export default AsyncTest;
现在,如果我想为这个组件创建一个 Jest 快照测试,那么我会写这样的东西:
import React from 'react';
import renderer from "react-test-renderer";
import AsyncTest from "./AsyncTest";
describe('Async Test', () => {
test('test', () => {
const test= <AsyncTest/>
expect(renderer.create(test).toJSON()).toMatchSnapshot();
});
});
这不起作用。我收到此错误:
TypeError:无法读取 null 的属性“样式”
at Window.getComputedStyle (A:\frontend\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\browser\Window.js:524:20) at copyStyles (A:\frontend\node_modules\react-bootstrap-typeahead\lib\containers\hintContainer.js:61:27) at HintedInput.componentDidMount (A:\frontend\node_modules\react-bootstrap-typeahead\lib\containers\hintContainer.js:113:9) at commitLifeCycles (A:\frontend\node_modules\react-test-renderer\cjs\react-test-renderer.development.js:10930:22)
这是 bootstrap typeahead 的已知问题吗?