Angular 角度:为什么没有错误?模式对属性不起作用?

Angular 角度:为什么没有错误?模式对属性不起作用?,angular,unit-testing,testbed,Angular,Unit Testing,Testbed,我正在写我的第一个角度测试,这里有一个问题。我正在测试一个组件,其中有一个自定义属性 <ng-container *isGranted="admin"> ... </ng-container> 但我还是犯了一个错误: 属性绑定被授予不被任何指令使用的权限 嵌入模板。确保属性名称拼写正确 正确,所有指令都列在“@NgModule.declarations”中 我哪里错了?我不想测试是如何被授予的行为,我只想检查分配给它的值是否正确。您使用的是指令,而无错误模式是忽略自定义

我正在写我的第一个角度测试,这里有一个问题。我正在测试一个组件,其中有一个自定义属性

<ng-container *isGranted="admin">
...
</ng-container>
但我还是犯了一个错误:

属性绑定被授予不被任何指令使用的权限 嵌入模板。确保属性名称拼写正确 正确,所有指令都列在“@NgModule.declarations”中


我哪里错了?我不想测试
是如何被授予的
行为,我只想检查分配给它的值是否正确。

您使用的是指令,而无错误模式是忽略自定义组件。请查看何时抛出错误,并出现适当的异常,表示需要包含指令

Property binding ${prop.name} not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations".

首先,您的
isgrated
-指令似乎没有添加到您的测试床配置中。请尝试将其作为声明或提供程序添加。@John当我将此声明添加到声明中时,编译器试图初始化属性,并在该服务(属性内部使用的服务)中抛出错误是否丢失我不确定这是否是原因,但您是否尝试过类似的方法?
TestBed.configureTestingModule({declarations:[isgrated]})
您还需要在您的测试床配置中提供您在isgrated指令中使用的服务。@luniroman因为该指令,所以我的观点是错误模式是忽略自定义组件,而不是directives@John没有its指令,也没有提供程序:)@luniroman文档正确:)没有模式忽略组件输入,输出uts但不是DirectivesSN指令是否与属性相同?我的情况是?@lunironom您使用的是结构指令如果您将普通指令与属性一起使用,则它将忽略它:)这有点混乱
Property binding ${prop.name} not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations".