Tag: 茉莉花

我如何用JasminetestingAngularJS服务?

(这里有一个相关的问题: Jasminetesting没有看到AngularJS模块 ) 我只是想testing一个服务,而不需要引导Angular。 我看了一些例子和教程,但我不会去任何地方。 我只有三个文件: myService.js:我在哪里定义一个AngularJS服务 test_myService.js:我为服务定义一个Jasminetesting。 specRunner.html:一个具有普通茉莉花configuration的HTML文件,以及我导入前两个其他文件和Jasmine,Angularjs和angular-mocks.js的地方。 这是该服务的代码(按照我预期的那样工作): var myModule = angular.module('myModule', []); myModule.factory('myService', function(){ var serviceImplementation = {}; serviceImplementation.one = 1; serviceImplementation.two = 2; serviceImplementation.three = 3; return serviceImplementation }); 因为我试图孤立地testing服务,所以我应该能够访问它并检查它们的方法。 我的问题是:如何在不引导AngularJS的情况下将服务注入到我的testing中? 例如,我怎样才能testing这样的Jasmine服务的方法返回的值: describe('myService test', function(){ describe('when I call myService.one', function(){ it('returns 1', function(){ myModule = angular.module('myModule'); //something is missing here.. expect( […]

QUnit vs茉莉花?

这两个testing框架的主要区别是什么? 我是一个全新的testing驱动开发,从一开始。

Jasmine.js比较数组

有没有办法在jasmine.js中检查两个数组是否相等,例如: arr = [1, 2, 3] expect(arr).toBe([1, 2, 3]) expect(arr).toEqual([1, 2, 3]) 两者似乎都不起作用。

茉莉花JavaScripttesting – toBe vs toEqual

假设我有以下几点: var myNumber = 5; expect(myNumber).toBe(5); expect(myNumber).toEqual(5); 上述两个testing都会通过。 在评估数字时, toBe()和toEqual()之间有区别吗? 如果是这样,我应该使用一个而不是另一个?

如何编写一个期望在Jasmine中抛出Error的testing?

我试图为Jasminetesting框架写一个testing,期望有一个错误。 目前我正在使用GitHub的Jasmine Node.js集成 。 在我的节点模块中,我有以下代码: throw new Error("Parsing is not possible"); 现在我试着写一个预期这个错误的testing: describe('my suite…', function() { [..] it('should not parse foo', function() { [..] expect(parser.parse(raw)).toThrow(new Error("Parsing is not possible")); }); }); 我也试过Error()和其他一些变种,只是不知道如何使其工作。

我如何模拟一个在Angularjs Jasmineunit testing中返回承诺的服务?

我有我的服务,使用myOtherService,这使远程调用,返回承诺: angular.module('app.myService', ['app.myOtherService']) .factory('myService', [myOtherService, function(myOtherService) { function makeRemoteCall() { return myOtherService.makeRemoteCallReturningPromise(); } return { makeRemoteCall: makeRemoteCall }; } ]) 要为myService进行unit testing,我需要模拟myOtherService ,使其makeRemoteCallReturningPromise()方法返回一个promise。 这是我如何做到的: describe('Testing remote call returning promise', function() { var myService; var myOtherServiceMock = {}; beforeEach(module('app.myService')); // I have to inject mock when calling module(), // and module() should come before any inject() […]

jasmine:asynchronouscallback未在由jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时

我有一个叫做requestNotificationChannel的angular度服务: app.factory("requestNotificationChannel", function($rootScope) { var _DELETE_MESSAGE_ = "_DELETE_MESSAGE_"; function deleteMessage(id, index) { $rootScope.$broadcast(_DELETE_MESSAGE_, { id: id, index: index }); }; return { deleteMessage: deleteMessage }; }); 我正在尝试使用jasmineunit testing此服务: "use strict"; describe("Request Notification Channel", function() { var requestNotificationChannel, rootScope, scope; beforeEach(function(_requestNotificationChannel_) { module("messageAppModule"); inject(function($injector, _requestNotificationChannel_) { rootScope = $injector.get("$rootScope"); scope = rootScope.$new(); requestNotificationChannel = _requestNotificationChannel_; }) […]

量angular器e2etesting案例下载pdf文件

谁能告诉我如何编写testing用例链接使用茉莉花框架下载PDF文件? 提前致谢。

将模拟注入到AngularJS服务中

我有一个AngularJS服务,我想unit testing它。 angular.module('myServiceProvider', ['fooServiceProvider', 'barServiceProvider']). factory('myService', function ($http, fooService, barService) { this.something = function() { // Do something with the injected services }; return this; }); 我的app.js文件有这些注册: angular .module('myApp', ['fooServiceProvider','barServiceProvider','myServiceProvider'] ) 我可以testingDI是这样工作的: describe("Using the DI framework", function() { beforeEach(module('fooServiceProvider')); beforeEach(module('barServiceProvider')); beforeEach(module('myServiceProvder')); var service; beforeEach(inject(function(fooService, barService, myService) { service=myService; })); it("can be instantiated", function() { expect(service).not.toBeNull(); […]