如何在Cypress组件测试运行程序中安装Angular组件



我试图在Angular中的新设置的Cypress组件测试运行器环境中安装一个Angular组件,比如:

import { ɵrenderComponent as renderComponent, ɵcompileComponent as compileComponent} from '@angular/core';
import '@angular/compiler';
import 'zone.js';
import { UT1DashEmployeesComponent } from './ut1-dash-employees.component';
/* eslint-env mocha */
/* global cy */
describe('UT1DashEmployeesComponent', () => {
beforeEach(() => {
const html = `
<head>
<meta charset="UTF-8">
</head>
<body>
<app-ut1-dash-employees></app-ut1-dash-employees>
</body>
`;
const document = (cy as any).state('document');
document.write(html);
document.close();
// Quick hack to get the component definition, which in our case is the first annotation.
compileComponent(UT1DashEmployeesComponent, (<any>UT1DashEmployeesComponent).__annotations__[0]);
renderComponent(UT1DashEmployeesComponent, {
host: document.body
});
});
it('works', () => {
cy.contains('UT1DashEmployeesComponent!').should('be.visible');
});
it('works again', () => {
cy.contains('UT1DashEmployeesComponent').should('be.visible');
});
});

但我得到以下错误:

错误组件"UT1DashEmployeesComponent"未解析:

  • 模板Url:/ut1-现金员工组件.pug
  • styleUrls:["./ut1短划线employees.component.style"]是否运行并等待"resolveComponentResources((">

由于此错误发生在每次挂钩之前,我们将跳过当前套件中的剩余测试:UT1DashEmployeesComponent

我能做什么?

Cypress还没有对Angular组件的本地支持。有一些第三方插件正在被合并到产品中(我认为(。

【编辑:Cypress现在原生支持Angular组件测试】

最新更新