我正在尝试使用 jest 和酶测试我在 reactjs 中构建的应用程序的响应能力。我怎样才能做到这一点?
我有一个侧边栏,当屏幕尺寸小于或等于 1024px 时,它会向左过渡并消失。我经历了这个 -弄清楚如何模拟反应组件测试stackoverflow 问题的窗口大小更改以模拟/模拟屏幕调整大小。然后我尝试使用像 getComputedStyle 这样的 DOM 函数来查看是否将过渡的 css 规则应用于侧边栏。但是我找不到我应用的转换规则。当我选择侧边栏,将其存储为全局元素并在浏览器控制台中对其执行 getComputedStyle 时,它起作用了。我究竟做错了什么?
测试文件
describe('App', () => {
let mountedApp: any;
const props: RouteComponentProps = {
...
} as RouteComponentProps;
const initialState = {
...
};
// Function that returns a new App mounted
const newApp = ((route: string) => {
if (!mountedApp) {
props.location.pathname = route;
mountedApp = mount(
<MemoryRouter initialEntries={[route]}>
<Provider store={configureStore([thunk])(initialState)}>
<App {...props} />
</Provider>
</MemoryRouter>,
{ attachTo: …Run Code Online (Sandbox Code Playgroud)