Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
Javascript AngularJasmine:使用超时绘制dom的测试组件_Javascript_Angularjs_Unit Testing_Jasmine - Fatal编程技术网

Javascript AngularJasmine:使用超时绘制dom的测试组件

Javascript AngularJasmine:使用超时绘制dom的测试组件,javascript,angularjs,unit-testing,jasmine,Javascript,Angularjs,Unit Testing,Jasmine,我的自定义指令中有以下功能: link: function (scope, element) { var editor = CKEDITOR.inline(element.find('div[contenteditable]')[0], {} 我想使用CKEDITOR.inline方法测试该指令是否链接,编辑器是否在元素下创建。所以我有一个测试: it('should compile', function () { var element = angular.elemen

我的自定义指令中有以下功能:

link: function (scope, element) {
    var editor = CKEDITOR.inline(element.find('div[contenteditable]')[0], {}
我想使用
CKEDITOR.inline
方法测试该指令是否链接,编辑器是否在
元素下创建。所以我有一个测试:

it('should compile', function () {  

    var element = angular.element('<directive></directive>');
    var compiled = $compile(element)(scope);
    $('body').append(compiled);

    expect(element.find('.ckeditor')).toExist();
});
因此,我的测试无法找到该类中的元素,因为它是同步执行的,而该元素是在测试之后添加到
inline
方法中的,因为
setTimeout
。如何测试它?

规格可以变成:

或者更好,可以使用:

beforeEach(function() {
    jasmine.clock().install();
});

afterEach(function() {
    jasmine.clock().uninstall();
});


it('should compile', function () {  
    ...
    jasmine.clock().tick(10);
    expect(element.find('.ckeditor')).toExist();
});
it('should compile', function (done) {  
    ...
    setTimeout(() => {
        expect(element.find('.ckeditor')).toExist();
        done();
    }, 10);
});
beforeEach(function() {
    jasmine.clock().install();
});

afterEach(function() {
    jasmine.clock().uninstall();
});


it('should compile', function () {  
    ...
    jasmine.clock().tick(10);
    expect(element.find('.ckeditor')).toExist();
});