草庐IT

jasmine-maven-plugin

全部标签

javascript - grunt Jasmine Node 测试运行两次

我设置了grunt来运行node.jsJasmine测试。出于某种原因,使用此配置,结果总是显示双倍的测试。这是我的配置:我正在使用jasmine-node插入grunt。/spec/some-spec.js:varmyModule=require('../src/myModule.js');describe('test',function(){it('works',function(done){setTimeout(function(){expect(1).toBe(1);done();},100);});});Gruntfile.js:module.exports=function

javascript - Jasmine 测试中未调用 AngularJS 指令链接函数

我正在创建一个在其link函数中调用服务的元素指令:app.directive('depositList',['depositService',function(depositService){return{templateUrl:'depositList.html',restrict:'E',scope:{status:'@status',title:'@title'},link:function(scope){scope.depositsInfo=depositService.getDeposits({status:scope.status});}};}]);目前该服务很简单:ap

javascript - Jasmine + AngularJS : How to test $rootScope. $broadcast 被调用参数?

我正在尝试编写一个单元测试来验证是否调用了$rootScope.$broadcast('myApiPlay',{action:'play'});。这是myapi.jsangular.module('myApp').factory('MyApi',function($rootScope){varapi={};api.play=function(){$rootScope.$broadcast('myApiPlay',{action:'play'});}returnapi;});这是我的单元测试:describe('Service:MyApi',function(){//loadtheser

javascript - 使用 Karma (Jasmine) 测试 AngularJS 工厂

我正在努力使用Karma+Jasmine测试AngularJS工厂。我无法将我的工厂注入(inject)OfficerValidationService变量。我做错了什么?注意:文件加载正确工厂:'usestrict';angular.module('darthvader').factory('OfficerValidationService',[function(){varOfficerValidationService={};OfficerValidationService.something=function(){returntrue;};returnOfficerValidat

javascript - Jasmine Node 完成未定义

一直在尝试简单的异步测试。安装jasmine-nodenpminstall-gjasmine-node然后编写一个简单的模块并测试。简单的模块。//weather.jsexports.get=function(city,callback){callback(city);};和一个测试套件。//weather-spec.jsvarlist=require("../modules/weather");describe("WeatherForecast",function(data){it('shouldgetweatherforLondon,UK',function(){list.get(

javascript - 在 Node.js 中使用 Jasmine 测试子 process.send

我有一个Node.js应用程序,它有一个main-process.js和一个child-process.js。main-process.js看起来像这样:varchildProcess=require('child_process');varjob=childProcess.spawn('node',["child-process.js"],{detached=true,stdio:['ipc']});我的child-process.js执行一些任务并通知父进程它的状态,它使用:exports.init=function(){//someprocessinghereprocess.se

javascript - $rootScope.digest 没有完成 Jasmine 中的 promise

我们目前正在尝试测试我们的Angular服务,它使用promise将值返回给Controller。问题是我们附加到.then的函数不会在Jasmine中被调用。我们发现在返回promise后将$rootScope.digest()添加到函数中允许调用同步promise,但它仍然不适用于异步promises。目前的代码是beforeEach(inject(function(Service,$rootScope){service=Service;root=$rootScope;}));it('getsalltheavailableproducts',function(done){servi

javascript - Jasmine:如何在 ES6 上监视导入的函数/构造函数?

我想知道如果我在babel中使用ES6导入/导出,我如何在Jasmine上监视/stub功能?importMobileDetectfrom'mobile-detect';it('shouldspyMobileDetect',()=>{MobileDetect=jasmine.createSpy('MobileDetect');});`第一个问题是我无法重写只读模块模块构建失败:SyntaxError:/Users/oleg/projects/rp/popup/lib/spec/popup.spec.js:"MobileDetect"isread-onlyit('shouldspyMob

javascript - 在 Jasmine 中,array.includes 不起作用(必须用其他函数代替)。为什么?

我的问题看起来很奇怪。我有一个带有一个新的、非常简单的函数的构造函数,它应该检查一个变量是否包含在一个数组中。它工作得很好(我在一个表单中使用这个函数)。但是...我无法对此函数编写任何单元测试,因为Karma/Jasmine看不到数组的“包含”函数。有人可以建议我该怎么做吗?这里的情况稍微简化了一点://要测试的构造函数vm.isNameAlreadyUsed=function(){//debutlogging:console.log("vm.allNames",vm.allNames);//output:vm.allNames['A','B','C']console.log("an

javascript - Grunt jasmine 测试在终端中失败但在浏览器中失败

我已经使用grunt和jasmine设置了一些测试,但是当我尝试在终端中运行测试时遇到了问题。我看到这个错误:>>Errorcaughtfromphantom.MoreinfocanbefoundbyopeningtheSpecRunnerinabrowser.当我在浏览器中运行specrunner文件时,我看到我的所有测试都通过了并且没有显示任何类型的错误。有谁知道这个问题的原因是什么?这是我的Gruntfile:module.exports=function(grunt){grunt.initConfig({pkg:grunt.file.readJSON('package.json