草庐IT

javascript - 测试 Jasmine 中自定义事件的处理

我想确保在触发自定义jQuery事件时,对象的方法作为事件处理程序被调用;但是单元测试似乎返回了假阴性,因为我的实现效果很好。(这是使用TwitterFlight和FlightJasmineextensions的测试套件的一部分,但这只是一个普通的Jasminespy。)describe('listeningforuiNeedsPlanevent',function(){varspy;beforeEach(function(){spy=spyOn(this.component,'getPlan');$(document).trigger('uiNeedsPlan');});it('ge

javascript - AngularJS Karma 测试中的 jQuery 触发事件

我正在尝试测试我正在编写的新指令。但是,我似乎无法在Karma/Jasmine中使用jQuery触发keydown事件。这是测试的简化版本:'usestrict';describe('',function(){var$compile;var$scope;beforeEach(inject(function(_$compile_,_$rootScope_){$compile=_$compile_;$scope=_$rootScope_.$new();}));describe('GettingTriggerToWork',function(){it('ShouldTriggeraKeyDo

javascript - 使用 Jasmine 在 JavaScript 中插入 WebSocket

我尝试测试onmessage是否是一个正确的函数。这是一个测试:describe(".init(address,window)",function(){beforeEach(function(){address='ws://test.address';window={};e={data:{}}spyOn(window,'WebSocket').and.returnValue(function(){return{onmessage:null}});spyOn(subject,'handleMessage');});it("shouldcreateaWebSocketclientwhich

javascript - 如何为包含来自另一个类/文件的全局变量的方法编写 Jasmine 测试?

我的测试失败的原因如下:ReferenceError:Can'tfindvariable:moving_canvas_contextinfile(line5)我了解测试失败的原因。它不理解该变量,因为它是在单独的JavaScript文件中定义的。但是,它是全局声明的并且在现实中有效。如何为这个clear_canvas函数编写jasmine测试?JavaScriptCanvas_Actions:(function(){window.Canvas_Actions=(function(){functionCanvas_Actions(){}Canvas_Actions.prototype.c

javascript - MatDialog 服务单元测试 Angular 6 错误

我有模式服务来打开、确认和关闭对话框,我正在制作它的单元测试文件,但我在Angular上遇到错误,这是代码。modal.service.ts@Injectable()exportclassModalService{constructor(privatedialog:MatDialog){}publicopen(modalComponent:ComponentType):Observable{letdialogRef:MatDialogRef;dialogRef=this.dialog.open(modalComponent,{maxWidth:'100vw'});console.log

javascript - 在 AngularJS 指令模板中的元素上测试 focus()

给定以下指令directive('myDirective',function(){return{restrict:'A',scope:{},replace:false,template:'',link:function(scope,element,attr){scope.onFocus=function(){console.log('gotfocus');};}};});我已经测试过焦点观察器可以在浏览器中工作,但我希望能够在单元测试中触发它。这是我尝试过的方法,但没有用。varelement=angular.element('');$compile(element)($scope);

javascript - 如何通过 Jasmine spy 将被拒绝/失败的 promise 返回到单元测试中的 Angular Controller

我正在使用jasmine来测试我的AngularController。我在.then(successCallback,errorCallback)中捕获错误和成功虽然它在实时功能的基础上运行良好,但我很困惑如何编写一个spy来返回错误,因为它总是在successCallback()中被捕获以下是Controller:-angular.module('myApp').controller('LoginCtrl',function($scope,$location,loginService,SessionService){$scope.errorMessage='';$scope.logi

javascript - jasmine.clock().tick() 不适用于 $timeout 和 debounce,但适用于 setTimeout

下面我有3个功能完全相同。每种调用setTimeout的方式不同,delay1()直接使用setTimeout,delay2()使用angularjs$timeout和delay3()使用lodashdebounce。它们都工作正常。问题出现在我用Jasmine测试的时候。setTimeout可以与jasmine.clock().tick()方法配合使用,但$timeout和debounce不适用't我有兴趣使用Jasmine进行去抖动。我知道我可以将$timeout.flush()与angularjs一起使用,但是$timeout和setTimeout在我使用的代码的其他地方给我带来

javascript - Protractor - 如何在配置文件中排除 spec 文件?

假设我有10个规范文件都命名为*********.test.js,我想对除文件Idontwantyou之外的所有9个文件运行我的测试.test.js.目前我在我的config.file中找到我的规范文件:specs:['*.test.js']-这将运行所有10个文件。如何让它运行所有9个测试文件但跳过Idontwantyou.test.js? 最佳答案 您可以通过将规范添加到conf.js文件的排除标记中来排除规范。您还可以添加模式以排除许多具有相似名称的测试脚本。这是如何做到的-exclude:['Idontwantyou.tes

javascript - 将 $stateParams 和 $state 注入(inject) Jasmine Angular js 测试变得未定义

我正在为我的DetailCtrl编写jasmine测试。我有10个json文件,每个文件的文件名都是这样1.json2.json3.json在我的数据文件夹中这是我的详细控制backpagecontrollers.controller('DetailCtrl',function($scope,$stateParams,$http){$http.get('data/'+$stateParams.listingId+'.json').success(function(data){$scope.extrainfo=data;});});细节Controller正在从我的数据文件夹中获取每个1