Angular单元测试:CUSTOM_ELEMENTS_SCHEMA错误
创始人
2024-10-23 23:00:49
0

在 Angular 单元测试中,当使用了自定义元素(Custom Elements)时,可能会出现 CUSTOM_ELEMENTS_SCHEMA 错误。这是因为 Angular 单元测试默认使用了 NO_ERRORS_SCHEMA 模式,它不支持自定义元素。

要解决这个问题,你可以在你的测试文件中添加 CUSTOM_ELEMENTS_SCHEMA 模式。下面是一个示例:

import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { Component } from '@angular/core';

@Component({
  selector: 'custom-element',
  template: '
Custom Element
', }) class CustomElementComponent {} describe('CustomElementComponent', () => { let fixture: ComponentFixture; let component: CustomElementComponent; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [CustomElementComponent], schemas: ['CUSTOM_ELEMENTS_SCHEMA'], // 添加 CUSTOM_ELEMENTS_SCHEMA 模式 }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(CustomElementComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); });

在上面的示例中,我们在 schemas 属性中添加了 'CUSTOM_ELEMENTS_SCHEMA',以告诉 Angular 单元测试支持自定义元素。

这样做后,你的单元测试应该能够正常运行,而不会报 CUSTOM_ELEMENTS_SCHEMA 错误。

相关内容

热门资讯

hh poker辅助器先试用!... hh poker辅助器先试用!wpk有透视吗(透视)技巧-总是了解真的是有挂;1、让任何用户在无需h...
we-poker正规吗!aap... we-poker正规吗!aapoker插件(透视)挂-真是曝光存在有挂we-poker正规吗透视方法...
wepoker私人辅助器!we... wepoker私人辅助器!wepoker俱乐部辅助器(透视)app-果然透视真的是有挂1、wepok...
wepoker-h5下载!we... wepoker-h5下载!wepoker破解器激活码(透视)脚本-确实详情存在有挂1、金币登录送、破...
wepoker透视功能下载!竞... wepoker透视功能下载!竞技联盟辅助(透视)插件-本来推荐是真的挂1.wepoker透视功能下载...
wepoker有辅助工具吗!h... wepoker有辅助工具吗!hhpoker透视方法(透视)脚本-原来详细真的有挂wepoker有辅助...
hhpoker真的有透视吗!w... hhpoker真的有透视吗!wepoker科技辅助器(透视)软件-本来关于是真的挂hhpoker真的...
WePOker有没有透视方法!... WePOker有没有透视方法!wepoker有机器人吗(透视)app-好像揭幕存在有挂1、WePOk...
佛手在线大菠萝辅助!wepok... 佛手在线大菠萝辅助!wepoker插件功能辅助器(透视)方法-确实总结存在有挂1、下载好wepoke...
哈糖大菠萝免费辅助器!wepo... 哈糖大菠萝免费辅助器!wepoker怎么增加运气(透视)挂-其实教你存在有挂1、哈糖大菠萝免费辅助器...