草庐IT

javascript - 找不到 Karma + Jasmine + TypeScript + Webpack 的源映射

我正在尝试使用Karma、Jasmine和Webpack测试(覆盖)我的TypeScript应用程序。通过以下,我能够成功运行测试,但无法正确生成覆盖率。我正在使用karma-remap-coverage(https://github.com/sshev/karma-remap-coverage),它看起来很简单。它看起来好像发生了一些有趣的事情(而且我得到了某种覆盖率报告)但是在这里和那里进行了一些调整,数字发生了巨大变化,我永远无法真正加载源map。这是基本设置:我有一个src目录,其中包含10个.ts文件。目前只有一个有相应的.spec文件。spec文件非常简单,足以证明我可以运

javascript - 获取 ReferenceError : Can't find variable: angular

我不熟悉yeoman及其使用的所有工具。我在yeoman中创建了一个测试项目并尝试在jasmine中运行测试规范。我已经使用cmd安装了jasmine插件:npm安装grunt-contrib-jasmine--save-dev在Gruntfile.js中添加了一个jasmine任务jasmine:{src:'/scripts/{,*/}*.js',specs:'test/spec/{,*/}*.js'},当我运行jasmine任务gruntjasmine时出现以下错误:-E:\PersonalProjects\yeoman-projects\test-app>gruntjasmine

javascript - "Error: Mismatched anonymous define()"与 Karma + RequireJS + Jasmine

我现在卡住了一段时间,试图设置和运行单元测试。我有一个AngularJS前端加载了针对生产优化的RequireJS和r.js,所以它很好地放在一个文件中。这行得通!执行单元测试是行不通的。到目前为止,这没什么特别的,只是从教程中复制了一个starter。tests/user/user.test.js:define(['angular','angular-mocks','app'],function(angular,app){describe('Unit:UserController',function(){beforeEach(module('user.app'));it('shoul

javascript - 类型错误 : module is not a function AngularJS & Jasmine

在我的示例应用程序中,我像这样测试运行器收藏夹Controller:varmodule=angular.module('AngularSampleApp',[]);varFavoritesController=module.controller('FavoritesController',functionfavoritesController($scope){$scope.phones=[{'name':'NexusS','snippet':'FastjustgotfasterwithNexusS.'},{'name':'MotorolaXOOM™withWi-Fi','snippet

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 - 如何 stub require()/expect 调用模块的 "root"函数?

考虑以下jasmine规范:describe("something.act()",function(){it("callssomefunctionofmymodule",function(){varmod=require('my_module');spyOn(mod,"someFunction");something.act();expect(mod.someFunction).toHaveBeenCalled();});});这工作得很好。像这样让它变绿:something.act=function(){require('my_module').someFunction();};现在

javascript - 如何编写可测试的 requirejs 模块

我是单元测试的新手,所以我可能遗漏了一些东西,但我应该如何构建requirejs模块以使它们完全可测试?考虑优雅的显示模块模式。define([],function(){"usestrict";varfunc1=function(){vardata=func2();};varfunc2=function(){returndb.call();};return{func1:func1}});据我所知,这是构建requirejs模块的最常见模式。如果我错了请纠正我!因此,在这个简单的场景中,我可以轻松地测试func1的返回值和行为,因为它是全局的。但是,为了测试func2我还必须返回它的引用

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 - 使用 css 定位器在 Protractor 中定位第二个、第三个、第四个……第八个元素

我一直在使用Protractor进行测试,除了通过css之外无法引用该元素,因为它只具有给定的类属性。问题是有超过7个元素具有此类名称。因此我使用语法element.all(by.css('h4.ng-binding')).first();对于第一个,它工作正常,但对于其他人,它不起作用!我使用与第一个逻辑相同的逻辑。这是我的代码片段,供其他人找到它们。element.all(by.css('h4.ng-binding')).second();element.all(by.css('h4.ng-binding')).third();element.all(by.css('h4.ng-b

javascript - javascript 测试用例中的 BeforeAll 和 AfterAll

我想在所有测试之前做点什么,然后再做?组织代码的最佳方式是什么?例如:备份一些变量->清除它们->测试一些东西->恢复备份。'beforeEach'和'afterEach'太贵了。谢谢! 最佳答案 一个非常简单的解决方案:describe("allo'mytests",function(){it("setupforalltests",function(){setItUp();});describe("actualtestsuite",function(){});it("teardownforalltests",function(){