jasmine

What is the difference between dispatchEvent() and triggerEventHandler() in angular unit testing using karma?

≯℡__Kan透↙ 提交于 2019-12-10 10:30:03
问题 I am writing unit test for a directive(called on input event), which is modifying an input value on a formControl. I've created a test component in my spec file for the same. I noticed a difference between triggerEventHandler() and dispatchEvent(), while dispatchEvent() was triggering the event correctly and directive was triggered, in the case of triggerEventHandler() event wasn't triggered. Can anyone let me know, what's the difference between them, apart from that dispatchEvent() is called

passing base url from command line in protractor

耗尽温柔 提交于 2019-12-10 10:15:46
问题 i am trying to test my angularjs app using protractor. my conf.js looks like this exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', capabilities: { 'browserName': 'chrome' }, specs: ['HomePageCtrl_spec.js'], chromeOnly: true, jasmineNodeOpts: { onComplete: null, isVerbose: false, showColors: true, includeStackTrace: true }, onPrepare: function() { browser.manage().window().setSize(1600, 1000); }, params : { url : 'test' }}; and i am runnig this command on command prompt

Protractor - button click calls the callback sooner than desired

*爱你&永不变心* 提交于 2019-12-10 10:13:10
问题 I have a protractor test for login page, that submits creds and checks if index page is loaded. I am passing a callback function to the button click's then function, assuming the callback will be invoked after the promise returned by click function is resolved. var protractor = require('protractor') describe('E2E: main page', function() { beforeEach(function() { browser.get('http://localhost:8001/login.html/'); }); it("login in the portal", function(){ var d = protractor.promise.defer();

How do I include lodash in my protractor test specs?

梦想与她 提交于 2019-12-10 10:06:17
问题 I want to use lodash functions in my protractor spec, I'm using _.forEach() to fill a form with values. How do I get lodash into my protractor script so that I can use it? I'm not asking how to use it in my app, but in the actual running protractor scripts 回答1: You can use the native Array.forEach(). If you need lodash do this: Get the node dependency. npm install lodash --save-dev Then use it in your test. var _ = require('lodash'); describe('foo', function() { it('should do stuff', function

Jasmine spyOn - method does not exist in jQuery anonymous function

梦想的初衷 提交于 2019-12-10 09:59:57
问题 Have searched for the answer to this problem on SO and other forums. Didn't find solution. I'm running into a problem where Jasmine cannot find a function inside of a jQuery code block, whether the Jasmine code is inside the jQuery function or not. $(function() { function foo(param1, param2) { // some code } describe("Foo function", function () { spyOn(window, 'foo'); foo(1, 2); it("Should be found by Jasmine", function(){ expect(window.foo).toHaveBeenCalled(); }); }); }); Error: foo() method

What's wrong with Angular service test?

做~自己de王妃 提交于 2019-12-10 09:46:30
问题 I've got a service calling external web service: angular.module('myApp.services', []) .service('autoCmpltDataSvc', function ($http) { var innerMatch = function (data) { return $.map(data, function (item) { return { fullName: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName, shortName: item.name, itemId: item.geonameId }; }); }; this.fetchFromGeonamesDb = function (request, response, matcher) { $http({ method: 'jsonp', url: 'http://ws.geonames.org

Unit test with spy is failing. Says spy was never called

倖福魔咒の 提交于 2019-12-10 07:40:49
问题 This is the code I'm testing eventsApp.factory('userData', ['userResource', function(userResource){ return{ getUser: function(userName, callback){ return userResource.get({userName:userName}, function(user){ if(callback) callback(user); }); }; }]); And this is the Jasmine test for it describe('userData', function(){ var mockUserResource; beforeEach(module('eventsApp')); beforeEach(function(){ mockUserResource = {get: function(){} }; module(function($provide){ $provide.value('userResource',

Why should I mock HTTP requests inside unit tests?

心不动则不痛 提交于 2019-12-10 06:51:24
问题 I'm working on a project and we've begun to write Jasmine unit tests. This application, like any good JS app does a lot of asynchronous fetching of data. I see that angular provides $httpBackend to mock up an HTTP request. I've also read and heard that it's a bad idea to test AJAX requests in your controller, and thus the raison d'etre for $httpBackend. Why is it not a good idea to test AJAX calls? How do big JS applications get around this fact? When does the actual testing of hitting the

Protractor: Correct use of waitReady.js file in my tests

倾然丶 夕夏残阳落幕 提交于 2019-12-10 06:26:28
问题 We are using browser.wait extensively throughout the entire test suite. It became a headache when managing different timeouts for different scenarios. I came across a waitReady function(https://gist.github.com/elgalu/2939aad2b2e31418c1bb), but I am unable to utilize it in my code. The directory looks like: (all files besides each other) . ├── conf.js ├── main.js ├── waitReady.js Main.js --->Contains all describe and it blocks require('./waitReady.js'); describe(...){ it{ code... expect

Jasmine spyOn with multiple returns

怎甘沉沦 提交于 2019-12-10 04:04:54
问题 I would like to test my angular application with Jasmine. So I created some tests, most of them work fine. But, one of my functions require the user to fill in an prompt. Tests can not fill this prompt, so I mocked them with spyOn(window,'prompt').and.returnValue('test') . This works, but only once. When I add two of my components (the function in which the prompt is located), I want to spyOn the first prompt with result 'test', and the second prompt with 'test2'. I tried doing this as