jasmine

testing Angular async services with Jasmine

给你一囗甜甜゛ 提交于 2019-12-22 00:10:05
问题 I am trying to test a real http call with Jasmine (integration test), but when i call a method that uses $http.get, it times out and the server never gets called. I know that I am supposed to inject the implementation of $http but not sure where that should happen. searchSvc app.service('searchSvc', ['$http', '$q', searchSvc]); function searchSvc($http, $q) { return { search: function(text) { console.log('svc.search called with ', text); // this does get called return $q.when($http.get('

nodemailer not sending mail when placed in protractor config afterLaunch() block

早过忘川 提交于 2019-12-21 23:59:50
问题 nodemailer not sending mail when placed in protractor config afterLaunch() block. It sends mail when placed in beforeLaunch() or onPrepare() blocks. Problem: Send HTML mail after protractor test run is complete. The framework generates a HTML file once the execution is complete. nodemailer to read the html content and send email config.js exports.config = { specs: ['../test_lab/execute.spec.js'], capabilities: { browserName: 'chrome', seleniumAddress: 'http://localhost:4444/wd/hub', },

How to unit test $location service search() method, in AngularJS?

[亡魂溺海] 提交于 2019-12-21 22:11:19
问题 How to create a unit test of AngularJS $location service search() method? I am using Jasmine+Karma for the test and AngularJS 1.3, and unit test is new to me :) This is my service, which is working fine in production btw: 'use strict'; (function () { angular.module('myApp') .service('myService', function ($location) { var _customerId = $location.search().id; /*jshint validthis:true */ this.customerId = _customerId; }); })() And this is my serviceSpec: describe('Service: mySerivce', function()

Jasmine test to test if the controller is defined

有些话、适合烂在心里 提交于 2019-12-21 21:07:19
问题 New to Jasmine tests for angular. I am trying to test if the controller I defined is defined or not to begin with but I am getting error saying Expected undefined to be defined. Here is my main code: // controller logic MatchController.js (function () { 'use strict'; angular.module('app.match') .controller('MatchController', MatchController); MatchController.$inject = ['APP_CONFIG', '$authUser', '$http', '$rootScope', '$state', '$stateParams', 'SearchService', 'ConfirmMatchService',

Nested it in Protractor/Jasmine

微笑、不失礼 提交于 2019-12-21 20:54:46
问题 Can I create a nested it in Protractor/Jasmine. it("outer it", function () { it("inner it", function () { expect(1).toBe(1); }); }); I am trying to execute it test cases inside a loop, and in every iteration I want to run a test, for example: it("outer it", function () { for(var i=0;i<10;i++){ it("inner it", function () { expect(1).toBe(1); }); } }); The reason I want to do it is that I want to initialize an array and then in a dynamically way to loop trough all the element and run a number

Mocha test case - are nested it( ) functions kosher?

ぐ巨炮叔叔 提交于 2019-12-21 09:16:49
问题 I have this case where I think I want to have nested it() test cases in a Mocha test. I am sure this is wrong, and I don't see any recommendations to do what I am doing, but I don't really know of a better way at the moment - basically, I have a "parent" test, and inside the parent test there's a forEach loop with all the "child" tests: it('[test] enrichment', function (done) { var self = this; async.each(self.tests, function (json, cb) { //it('[test] ' + path.basename(json), function (done)

jasmine spy on nested object

谁都会走 提交于 2019-12-21 08:05:10
问题 My service object looks like this: var appService = { serviceOne: { get: function(){} }, serviceTwo: { query: function(){} } } I would like to mock appService,something like: expect(appService.serviceTwo.query).toHaveBeenCalled(); How would I go about doing it? 回答1: OK I got this working with this: appService: { serviceOne: jasmine.createSpyObj('serviceOne', ['get']), serviceTwo: jasmine.createSpyObj('serviceTwo', ['query']) } I hope it is the right way to do. 回答2: Just replace the function

Testing a $interval with Jasmine in PhantomJS

杀马特。学长 韩版系。学妹 提交于 2019-12-21 07:47:41
问题 It appears that my interval is never triggered. I have a directive which contains a $interval and I want to test it. I've removed all the directive-related code and added this piece instead in its controller: window.called = 0; window.interval = $interval(function () { window.called++; console.log('interval ' + window.called); // 4 }, 10); console.log('initialized'); // 1 The test looks like this: describe('myDirective', function () { beforeEach(module('myModule')); beforeEach(function(

jasmine unit testing - testing for an undefined property of an object

无人久伴 提交于 2019-12-21 06:48:08
问题 I have the following statement expect(A.["BAR"].name).toEqual("foo"); which due to the fact my object A has the top level property "BAR" and bar has the value "foo" passes. I'd like to test my structure to confirm a property "NONEXISTINGPROP" has not be defined. e.g. expect(A.["NONEXISTINGPROP"].name).not.toBeDefined(); However I seem to get "TypeError: A.[NONEXISTINGPROP] is undefined" in the jasmine test runner this is exactly what I want to confirm. Any idea why Jasmine is crying. I was

How do you mock Angular service that is a function?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 06:02:03
问题 We have a what we call a CORShttpService , which is basically a wrapper aroung the $http service, but encapsulates some CORS functionality that we need. I'm now writing some tests for a service that has the CORShttpService injected into it. This service has code like this: CORShttpService({method: requestMethod, url: getUrl(path), data: data}). success(function(data, status, headers) { //do success stuff }). error(function(data, status, headers) { //do error stuff }); I want to mock the call