Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing useShadowDom的AngularDart单元测试:false_Unit Testing_Dart_Angular Dart - Fatal编程技术网

Unit testing useShadowDom的AngularDart单元测试:false

Unit testing useShadowDom的AngularDart单元测试:false,unit-testing,dart,angular-dart,Unit Testing,Dart,Angular Dart,我正在尝试为useShadowDom设置为false的angular.dart(1.1.2)组件编写单元测试。如果useShadowDom设置为true,我似乎无法找到引用组件范围的方法 @Component( selector: 'test_component', templateUrl: 'test_component.html', useShadowDom: false ) class TestComponent { bool clicked = fals

我正在尝试为useShadowDom设置为false的angular.dart(1.1.2)组件编写单元测试。如果useShadowDom设置为true,我似乎无法找到引用组件范围的方法

@Component(
    selector: 'test_component',
    templateUrl: 'test_component.html',
    useShadowDom: false
)
class TestComponent {

    bool clicked = false;
    clickHandler() {
        clicked = true;
    }
}
然后在我的测试中:

inject((TestBed tb) async {
        Scope s = tb.rootScope.createChild({"clicked" : false});
        Element el = tb.compile("<test_component></test_component>", scope: s);

        microLeap();
        await tb.rootScope.apply();

        ShadowRoot root = await el.shadowRoot;

        // When useShadowDom: true, then use root here instead
        Element theButton = el.querySelector("#the_button");
        theButton.click();

        microLeap();
        await testBed.rootScope.apply();

        // If I do this with useShadowRoot: true, then it works perfect 
        // (true) but root is null with useShadowDom: false and if I pass 
        // element, then scope.context is just a map with the original
        // values (clicked = false).
        print((testBed.getScope(root).context as TestComponent).clicked);

        // This just prints the original values (clicked = false)
        await s.context.forEach((String key, Object val) async => print("$key : $val"));

});

您是刚开始使用Angular.dart还是希望引入单元测试的成熟项目?它是一个已有单元测试的现有项目(大约9个月)。我们在新的单元测试中添加了新的功能,但是遇到了这个问题。在这个具体的例子中,上面的工作让我们。。。但这似乎是测试床上的一个bug。您是刚开始使用Angular.dart还是希望引入单元测试的成熟项目?它是一个已有单元测试的现有项目(大约9个月前)。我们在新的单元测试中添加了新的功能,但是遇到了这个问题。在这个具体的例子中,上面的工作让我们。。。但这似乎是测试床上的一个bug。
dynamic getComponentContext(Node el, Function typeCallback, TestBed tb) {
    if(el is Element && el.childNodes != null && el.childNodes.isNotEmpty) {
        Scope s = tb.getScope(el);
        if(typeCallback(s.context)) {
            return s.context;
        }
        else {
            for(Node childNode in el.childNodes) {
                var c = getComponentContext(childNode, typeCallback, tb);
                if(c != null) {
                    return c;
                }
            }
        }
    }
    return null;
}