jasmine

Jquery trigger() doesnt work in angular scenario test runner in end2end test

旧街凉风 提交于 2019-12-23 02:21:27
问题 I am aware that binding to jquery events in angular "controller" is not in line with this framework philosophy but it allows me to migrate views in asp.net mvc project to angular step by step. This works on runtime but i can't test this. If I have binded jquery event 'keydown' on input field in "controller" and I try to trigger() this event in my test scenario (I am using angular-scenario.js) this event simply is not recieved in "controller". I cant use input().enter() as this input is not

Mock angular factory that uses $q in Jasmine

ε祈祈猫儿з 提交于 2019-12-23 02:04:27
问题 Surely this has been asked before but I can't find it. I need to mock a factory, but the mock itself needs to use $q, and I end up in a chicken and egg situation with regards to calling module() after inject(). I looked at this question which advises doing a spyOn, which works for services because it is a singleton, but I am calling new on the function returned by my factory, creating a new instance each time, so that won't work... var app = angular.module('app', []); app.factory(

Unable to get property then of undefined?

我的未来我决定 提交于 2019-12-23 02:01:37
问题 Trying to run a unit test for my angular httpbased service: angular.module('myApp').factory('httpService',function($http) { return { sayHello:function(usr){ $http.get('/api/doit').then( function(result){ return 'hello '+usr; }); } } }); This is the test: it('should say hello from httpservice', function() { var returnData = 'hello Tomss'; httpBackend.expectGET('/api/doit').respond(returnData); var returnedPromise = httpService.sayHello('Tom'); var result; returnedPromise.then(function(response

Jasmine clock tick & Firefox: failing to trigger a Q.delay method

自古美人都是妖i 提交于 2019-12-22 20:02:52
问题 Lazy loading tests: I am trying to build a test for Jasmine to test a method that uses Q.delay. To go around the 10 seconds wait i'm using Jasmine's clock: jasmine.Clock.tick(10010); This works on Chrome but does not work on Firefox. I saw that the delay method of Q utilized setTimeout so I can't see any reason for the different behaviors. Any ideas why it fails on Firefox? 回答1: With jasmine 2.0 and Q at the v1 tag, I'm able to run this spec: describe("testing", function() { beforeEach

Jasmine clock tick & Firefox: failing to trigger a Q.delay method

℡╲_俬逩灬. 提交于 2019-12-22 20:00:00
问题 Lazy loading tests: I am trying to build a test for Jasmine to test a method that uses Q.delay. To go around the 10 seconds wait i'm using Jasmine's clock: jasmine.Clock.tick(10010); This works on Chrome but does not work on Firefox. I saw that the delay method of Q utilized setTimeout so I can't see any reason for the different behaviors. Any ideas why it fails on Firefox? 回答1: With jasmine 2.0 and Q at the v1 tag, I'm able to run this spec: describe("testing", function() { beforeEach

Inject $log service on simple Jasmine test

天涯浪子 提交于 2019-12-22 18:18:48
问题 Yes, I'm completely new to Angular and Jasmine, and I can't figure out how to inject a mock $log for my test. This is the test: (function () { 'use strict'; describe('basic test', function(){ it('should just work', function(){ var $log; beforeEach(inject(function(_$log_){ $log = _$log_; })); $log.info('it worked!'); expect($log.info.logs).toContain(['it worked!']); }); }); }()) This fails on the inject line with an error: TypeError: Cannot set property 'typeName' of undefined What am I

Cannot inject service into its Angular unit test

大城市里の小女人 提交于 2019-12-22 17:54:58
问题 I'm trying to unit test an Angular service using: angular 1.3.8 angular-mocks 1.3.8 karma 0.13.19 jasmine 2.4.1 node 0.10.33 OS: Windows 7 Browser: PhantomJS 2.1.3 The problem is, the service I wish to test ( MyService ) is not injected in the test file by the angular-mocks lib (i.e. the 'inject' method does nothing). My code looks as follows: main.js (function() { 'use strict'; angular.module('module', [ 'ngCookies', 'ngSanitize' ]); })(); service.js (function () { 'use strict'; angular

Karma-Jasmine: How to test $translate.use?

无人久伴 提交于 2019-12-22 17:49:15
问题 THE SITUATION: I am testing the function that allow the user to select a language. But I am getting the following error: TypeError: $translate.use is not a function I have seen similar questions in SO and other forums but they are not working for me. THE CODE: The configuration: app.config(function($stateProvider, $urlRouterProvider, $translateProvider) { $translateProvider.useSanitizeValueStrategy('sanitize'); $translateProvider.translations('EN', { "MY_ACCOUNT": "My account", "PROJECT_LIST"

Spy and callThrough native WebSocket constructor with Jasmine

谁都会走 提交于 2019-12-22 13:59:00
问题 I'm trying to spy on native WebSocket constructor, so I wrote: it("should spy and call through WebSocket constructor", function (done) { var WSspy = spyOn(window, "WebSocket").and.callThrough(); var ws = new WebSocket("ws://some/where"); expect(WSspy).to.toHaveBeenCalledWith("ws://some/where"); }); but it results in error: TypeError: Failed to construct 'WebSocket': Please use the 'new' operator, this DOM object constructor cannot be called as a function. How should I callThrough such

Unit testing logic inside promise callback

Deadly 提交于 2019-12-22 12:23:24
问题 I have an ES6 / Aurelia app that I am using jasmine to test. The method I am trying to test looks something like this: update() { let vm = this; vm.getData() .then((response) => { vm.processData(response); }); } Where this.getData is a function that returns a promise. My spec file looks something like this: describe('my service update function', () => { it('it will call the other functions', () => { myService = new MyService(); spyOn(myService, 'getData').and.callFake(function() { return new