简体   繁体   English

如何在Jasmine中编译嵌套的Directives进行单元测试?

[英]How to compile nested Directives in Jasmine for unit test?

I am currently compiling a directive for unit test $compile('custom directive' )(scope); 我目前正在编译单元测试$ compile('custom directive')(范围)的指令; It does compile the directive, but the custom directives nested within the directive remain uncompiled. 它确实编译了该指令,但嵌套在指令中的自定义指令仍然是未编译的。 Is there a way to compile nested directives? 有没有办法编译嵌套指令?

I'll answer my own question for anyone who sees this. 对于那些看到这个的人,我会回答我自己的问题。 The reason they were not compiling was because I needed to reference the nested directives as a dependency within the parent directive. 他们没有编译的原因是因为我需要将嵌套指令作为父指令中的依赖项引用。 You do not need to do this in angular for it to work on the front-end. 你不需要在角度上这样做,因为它可以在前端工作。 It doesn't work with Jasmine because it recognizes it as just a plain html element(this is expected and valid) unless you specify the dependency for it to recognize it as an angular directive. 它不适用于Jasmine,因为它只将它识别为一个简单的html元素(这是预期的和有效的),除非你指定它的依赖关系将它识别为一个angular指令。 This is also the reason why Jasmine didn't throw a dependency error. 这也是Jasmine没有抛出依赖错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM