Я пытаюсь протестировать простой компонент React с ts-jest , который содержит компоненты Office Fabric React:
import { Stack, Text } from "office-ui-fabric-react";
import * as React from "react";
import "./ListItem.scss";
export interface ListItemProps {
title: string;
}
export const ListItem = (props: ListItemProps) => (
<Stack className={"list-item"} data-is-focusable={true} verticalAlign="center">
<Text>{props.title}</Text>
</Stack>
);
Спецификация:
import * as Adapter from "enzyme-adapter-react-16";
import { configure, shallow } from "enzyme";
import { ListItem, ListItemProps } from "./ListItem";
const item: ListItemProps = { title: "Hello" };
describe("ListItem", () => {
configure({ adapter: new Adapter() });
it("should render my component", () => {
const wrapper = shallow(ListItem(item));
expect(true).toBe(true);
});
});
но получая следующую ошибку при запуске теста:
TypeError: document.createElement не является функцией
в Stylesheet.Object..Stylesheet._createStyleElement (/ Users / joebloggs / Documents/Projects/Add-In/node_modules/@uifabric/merge-styles/lib-commonjs/Stylesheet.js:250:33) в Stylesheet.Object..Stylesheet._getStyleElement (/ Users / joebloggs / Documents / Projects / Add-In/node_modules/@uifabric/merge-styles/lib-commonjs/Stylesheet.js:235:33) в Stylesheet.Object..Stylesheet.insertRule (/ Пользователи / joebloggs / Документы / Проекты / Надстройка / node_modules / @ uifabric /merge-styles / lib-commonjs / Stylesheet.js: 167: 71) в applyRegistration (/Users/joebloggs/Documents/Projects/Add-In/node_modules/@uifabric/merge-styles/lib-commonjs/styleToClassName.js:269: 20) в Object.styleToClassName (/ Users / joebloggs / Documents / Projects/Add-In/node_modules/@uifabric/merge-styles/lib-commonjs/styleToClassName.js:289:5) в mergeCss (/ Users / joebloggs / Documents / Projects / Надстройка / node_modules / @ uifabric / merge-styles/lib-commonjs/mergeStyles.js:45:37) в Object.mergeStyles (/Users/joebloggs/Documents/Projects/Add-In/node_modules/@uifabric/merge-styles/src/mergeStyles.ts:26:9)в _constructFinalProps (/Users/joebloggs/Documents/Projects/Add-In/node_modules/@uifabric/foundation/lib-commonjs/slots.js:218:36) в результате (/ Users / joebloggs / Documents / Projects / Add-In/node_modules/@uifabric/foundation/lib-commonjs/slots.js:99:22) в _renderSlot (/Users/joebloggs/Documents/Projects/Add-In/node_modules/@uifabric/foundation/lib-commonjs/slots.js: 235: 41)