代码之家  ›  专栏  ›  技术社区  ›  j3ff

角度4+Jest预设角度:使用从文件导入的触发器在主机上测试动画

  •  0
  • j3ff  · 技术社区  · 7 年前

    我在运行测试时遇到问题 Jest-Preset-Angular

    示例.animation.ts

    import { trigger } from '@angular/animations';
    
    export const ExampleAnimationHost = { '[@example]': '' };
    export const ExampleAnimationTrigger = trigger('example', []);
    

    示例.component.ts

    import { Component } from '@angular/core';
    import { ExampleAnimationHost, ExampleAnimationTrigger } from './example.animation';
    
    @Component({
      selector: 'app-example',
      templateUrl: './example.component.html',
      styleUrls: ['./example.component.scss'],
      animations: [ExampleAnimationTrigger],
      host: ExampleAnimationHost,
    })
    export class ExampleComponent { }
    

    复制粘贴 animations 的属性 @Component 装饰我的测试通过…否则它会失败,因为它似乎没有找到动画声明。

    1 回复  |  直到 7 年前
        1
  •  4
  •   j3ff    7 年前

    如果有人有同样的问题,我会回答我自己的问题。

    here 指定需要将 animations 所有物 这个 styleUrls 中的属性 @Component 室内装修设计师

    import { Component } from '@angular/core';
    import { ExampleAnimationHost, ExampleAnimationTrigger } from './example.animation';
    
    @Component({
      animations: [ExampleAnimationTrigger], // must be place before styleUrls
      host: ExampleAnimationHost,
      selector: 'app-example',
      templateUrl: './example.component.html',
      styleUrls: ['./example.component.scss'],
    })
    export class ExampleComponent { }
    

    瞧!