我一直在try 让Storybook交互测试适用于我们的生产Angular 应用程序.我们已经有了使用Karma/Jasmine的现有测试,但我们希望为更多的用户界面驱动测试实现Storybook测试.
故事在组件文件旁边的.stories.ts
个文件中定义,如下所示:
import { Meta, Story } from '@storybook/angular';
import { userEvent, within } from '@storybook/testing-library';
import { CounterComponent } from "./counter.component";
export default {
component: CounterComponent,
title: 'Components/Counter',
excludeStories: /.*Data$/,
} as Meta;
const Template: Story = () => ({});
export const Default = Template.bind({});
Default.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
await expect(canvas.getByTestId('text').innerHTML).toBe('0');
await userEvent.click(canvas.getByRole('button'));
await expect(canvas.getByTestId('text').innerHTML).toBe('1');
};
But when building or running Storybook tests I run into the error cannot find name 'expect'
or expect is not defined
.
I have tried explicitly importing expect
from @jest/globals
but this is not possible.
I have tried looking into assigning various things to global
in preview.ts/js
but failed to fix my errors.
我已经在这个存储库中重新创建了它https://github.com/bertcardinaels/storybook-angular-test
如果有任何帮助或指点,我们将不胜感激,因为这should是可能的,对吗?