单元测试aurelia自定义元素

时间:2016-12-06 16:46:06

标签: unit-testing aurelia

我正在使用视图测试一个简单的折叠自定义元素:

interface Animal { public function getAge(); } // The same thing for the class Dog class Cat implements Animal { public function getAge() { // code to calculate age } ... } public function calculateAge(Animal $animal) { echo $animal->getAge(); } $dog = new Dog(); calculateAge($dog); $cat = new Cat(); calculateAge($cat);

并查看模型:

<template> <button click.delegate="toggle()"></button> <div show.bind="collapsed"> <slot></slot> </div> </template>

我的测试看起来像这样:

export class Collapse { collapsed: boolean; toggle() { this.collapsed = !this.collapsed; } }

我能以某种方式摆脱setTimeout吗?

1 个答案:

答案 0 :(得分:3)

  it('should show content on flag change', done => {
    let div: HTMLDivElement;
    component.create(bootstrap)
      .then(() => {
        div = <HTMLDivElement>document.querySelector('div');
        const style = window.getComputedStyle(div);
        expect(style.display).toBe('none');
        component.viewModel.toggle();
      })
      .then(() => {
        const style = window.getComputedStyle(div);
        expect(style.display).toBe('block');
      })
      .then(done);
    });
  });