草庐IT

Karma-Jasmine

全部标签

javascript - Uncaught ReferenceError : jasmineRequire is not defined

我的测试有问题,当我运行它们时出现此错误:0909201514:55:27.174:INFO[Chrome45.0.2454(MacOSX10.10.1)]:Connectedonsocket9aXAoBK8a1zKw9IVAAAAwithid22794373Chrome45.0.2454(MacOSX10.10.1)ERRORUncaughtReferenceError:jasmineRequireisnotdefinedat/Users/agarcia/Projects/affiliate-suite/node_modules/karma/jasmine/lib/boot.js:1

javascript - 在 Angular 单元测试中模拟 ngResource

我有一个看起来像这样的ngResourceMockFactory:(function(){'usestrict';angular.module('app').factory('NgResourceMock',ngResourceMockFactory);ngResourceMockFactory.$inject=[];functionngResourceMockFactory(){functionNgResourceMock(){varcontext=this;context.$promise.then=function(){context.prototype.$promise.the

javascript - 按类不返回元素的 Angular Fixture DebugElement 查询

正如Angular.io框架测试文档所建议的,我一直在尝试使用AngularTestbed+Karma测试运行器来使用DebugElement查询。我创建了一个jqwidgetsTree组件,它生成类'.jqx-tree-item-li'的li元素。以下在DOM测试中直接使用javascript的测试通过了GREEN:it('Elementsofclassjqx-tree-item-lifoundusinggetElementsByClassName',(done)=>{this.fixture.whenStable().then(()=>{varelementArray=docume

javascript - 如何检查按钮是否禁用或不成 Angular ?

我正在尝试添加模板驱动形式的单元测试用例。如何检查submit按钮在初始阶段被禁用,并在用户输入所有有效的字段时启用。这是表格https://stackblitz.com/edit/angular-a8q2zr?file=src%2Fapp%2Fapp.component.html单元测试用例https://stackblitz.com/edit/angular-testing-5m3qwm?file=app%2Fapp.component.spec.tsimport{ComponentFixture,TestBed,async}from'@angular/core/testing';

javascript - AngularJS 测试 $httpBackend.flush() 导致错误

我正在尝试使用jasmine对我为Spotify创建的AngularJS服务进行一些测试。但是在测试promises时,我的测试总是出错。我的测试目前是这样的:describe('Spotify.search',function(){var$httpBackend;var$rootScope;varSpotify;varapi='https://api.spotify.com/v1';beforeEach(inject(function(_Spotify_,_$httpBackend_,_$rootScope_){Spotify=_Spotify_;$httpBackend=_$htt

javascript - Angular Karma Jasmine - 测试功能

基本上我必须测试下面这个函数,我正在从文本文件中读取$window.resolveLocalFileSystemURL(cordova.file.dataDirectory,function(dir){varpath='somefile.txt';dir.getFile(path,{create:true},function(file){file.file(function(file){varreader=newFileReader();reader.onloadend=function(){resolve(this.result);}reader.readAsText(file);}

javascript - Jasmine : Timeout - Async callback was not invoked within timeout

我需要测试一个从url加载图像的AngularJs服务。这是我的服务:/*globalangular,Image*/(function(){'usestrict';functionSourceLoader($q,$log){/***Loadanimagefromurlandreturnapromisewhichisresolvedwhenimageisloadingisdone.*Itreturntheimagesobjectasresolvedpromise.*@paramurlsourceoftheimage*@returns{Promise}unresolvedpromiseof

javascript - 使用 Jasmine 或任何其他替代方案在 Node 上运行测试 .mjs/ESM

由于--experimental-modulesCLI开关(即node--experimental-modules),我的基于Node的项目是在Node上使用原生ES模块支持实现的.显然,当我使用Jasminenode--experimental-modules./node_modules/jasmine/bin/jasmine运行规范时,出现以下错误:Error[ERR_REQUIRE_ESM]:MustuseimporttoloadESModule是否可以在Node中通过ES模块使用Jasmine?如果不是,是否有任何替代方法不使用框架(例如,使用npm脚本运行测试)?

javascript - 使用 jasmine 进行 jquery 测试

我是Jasmine的初学者。我不知道如何使用jasmine测试以下jquery代码。if($('.data-block').length>0){$('.span4:even','.data-block').addClass('even');$('.span4:odd','.data-block').addClass('odd');}你能告诉我如何使用jasmine为这个jquery程序编写测试代码吗?谢谢你的回答。 最佳答案 您可以使用Jasmine-JQuery插件并针对注入(inject)的DOM进行测试:https://git

javascript - 如何让 Karma + Webpack 找到模块?

在webpack通过Karma测试运行器将它们组合在一起后,我想在一堆模块上运行我的测试,但是每当我运行我的测试时,Karma都会说,"Error:Cannotfindmodule"hello.js"athttp://localhost:9877/base/src/hello.spec.js?d301966ffc1330826574d9d8fff5a644c3390c68:47"我有一个规范文件:vara=require('hello.js');describe("atesttest",function(){it("humperdinktest",function(){expect(a