如何测试角镖装饰器?

时间:2014-06-09 18:54:25

标签: dart karma-runner angular-dart

我正在尝试对角落飞镖装饰器进行单元测试,但无法通过组件编译阶段。

我试图效仿这个例子:https://github.com/vsavkin/angulardart-sample-app/blob/master/test/unit/agenda_item_component_test.dart

问题在于业力似乎没有等待编译阶段完成而只是跳过测试。

part of webpuzzle_spec;

digest() {
  inject((TestBed tb) {
    tb.rootScope.apply();
  });
}

compileComponent(String html, Map scope, callback) {
  print("This logs");
  return async(() {
    inject((TestBed tb) {
      print("this should log but doesn't");
      final s = tb.rootScope.createChild(scope);
      final el = tb.compile(html, scope: s);
      microLeap();

      digest();

      callback(el.shadowRoot);
    });
  });
}

testWpDropdownMenu() {

  group("[WpDropdownMenu]", () {

    setUp(setUpInjector);
    tearDown(tearDownInjector);

    setUp((){
      module((Module _) => _..type(TestBed)..type(WpDropdownMenu));
    });

    html() => '''<span class="dropdown-toggle">
                  <button type="button" class="btn btn-default">menu to click</button>
                  <ul class="dropdown-menu">
                    <li>menu item</li>
                  </ul>
                </span>''';

    test("should open menu on click", compileComponent(html(), {}, (shadowRoot) {
      print("this never logs :(");
      shadowRoot.click();
      digest();
      var toggleableMenu = shadowRoot.querySelector('.dropdown-menu');
      expect(toggleableMenu.style.display, equals('none'));
      expect(true, equals(false)); // this should make the test fail
    }));

  });
}

此代码有什么问题?有没有一个很好的例子可以解释如何测试组件/装饰器,只使用angular.dart和karma?

0 个答案:

没有答案
相关问题