我正在尝试(并且失败)为此行代码编写测试
const dialogScope = parent.angular.element(window.frameElement).scope();
dialogScope.close();
这是我的考验
it('does as planned', function(){
var frameElement = document.createElement('iframe');
var test = 'test';
window['__defineGetter__']('frameElement', function(){
return frameElement
});
var ngElementFake = function(frameElement) {
return {
scope: function() {
return {
toggleChildElement: true,
field: scope.field
}
}
}
}
const parentStub = {
angular: {
element: ngElementFake
}
}
window.parent['__defineGetter__']('angular', function(){
return parentStub
});
element.isolateScope().close();
// will add expect later
});
但我不断收到TypeError:
TypeError: parent.angular.element is not a function
我假设它抱怨我在测试中通过的不是函数,但是我不确定。我试图进行Google搜索,但找不到任何有用的信息。有什么更好的写方法?