jasmine

spying upon a global function using jasmine-node

不羁的心 提交于 2019-12-07 22:03:45
问题 I am using jasmine-node to do unit testing on javascript code. I have a number of global functions which I would like to spyOn and allow the call to make it though to the original implementation. See the code below as an example. For a reason I cannot explain, I am seeing an error "globalFunction() method does not exist". Can someone tell me why jasmine is not able to find this globalFunction method which I understand to be in global scope. I appreciate the help var globalFunction = function(

How to fake being offline in Jasmine?

守給你的承諾、 提交于 2019-12-07 21:47:09
问题 I have a javascript function which is supposed to behave differently when offline than online as a safeguard. I would like to have a Jasmine unit test which tests the function in both offline and online modes - e.g., // offline describe('When there is no connection to the internet', function() { beforeEach(function(){ spyOn(navigator, 'onLine').and.returnValue(false); }); it('offline behavior happens', function() { myFunction(); expect(something).not.toHaveBeenCalled(); }); }); // online

Angularjs unit testing resolving promises

…衆ロ難τιáo~ 提交于 2019-12-07 21:24:55
问题 I'm probably doing this wrong but I can't figure out how to fix it. I want to test a controller that uses a resource (ngResource) and I want to use a Spy as a test double for the resource so it doesn't actually do the http call. In the code below I just want to test the search function in the controller. Controller: controllers = angular.module('app.controllers'); controllers.controller('landingCtrl', ['$scope', '$q', 'categoryResource', function ($scope, $q, categoryResource) { $scope.search

how to skip to next describe() upon error in previous describe? jasmine test

不羁的心 提交于 2019-12-07 18:54:50
问题 i'm using such code in order to stop the entire describe upon an error in one of the it() functions: if(this.results_.failedCount > 0) { //next step will finish the test jasmine.Queue.prototype.next_ = function () { // to instead skip to the end this.onComplete(); } } i got it from: How can I make jasmine.js stop after a test failure? however, if i have few describe blocks in the file, and the first describe fails, i would like it to continue to the next describe and not kill the entire test.

Running Jasmine Integration Tests in Parallel via Selenium Grid

▼魔方 西西 提交于 2019-12-07 18:11:12
问题 I've playing around with jasmine and selenium webdriver for browser automation via node.js. What do I need to configure in order to run tests in parallel? I understand that on a java stack TestNG is often used to run parallel tests, what would be the best tool or configuration to run parallel selenium tests using jasmine and node.js? 来源: https://stackoverflow.com/questions/32211695/running-jasmine-integration-tests-in-parallel-via-selenium-grid

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

余生颓废 提交于 2019-12-07 18:01:26
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 part of model (as I said on beginning...). Question: is it possible to trigger event from scenario? If

Protractor/Jasmine drag and drop only grabbing text not the element

别来无恙 提交于 2019-12-07 17:45:22
问题 I have a Protractor/Jasmine E2E Automation test that is to drag and drop a couple of collapsible panels to change the order and just verify they the elements have been moved. I'm currently running latest versions of Protractor, Jasmine, and webdrivers (tests run in IE 11) EDIT: Found out we're using ng-dragula to perform the drag and drops. I'm assuming protractor just isn't playing nicely with this. I'll do more digging about it, but still curious to know if there's a work around. /end edit

How to deal with sessionStorage locally in FF (for testing)

故事扮演 提交于 2019-12-07 16:28:58
问题 I'm trying to write tests for all my JS, and the tests (I'm using Jasmine) are run locally in the browser. Due to security restraints(?) sessionStorage does not work locally (viewing file:///... in the browser) in Firefox. Quick example: window.sessionStorage.setItem('foo', 'bar'); This gives "Error: Operation is not supported". I tried overriding window.sessionStorage with my own mock methods, but with no luck. The only solution I have at the moment is to put everything related to

AngularJS test - inject $location causes error

情到浓时终转凉″ 提交于 2019-12-07 15:39:48
问题 So this one is driving me crazy, whenever i try to inject $location to one of my tests i get the following error: TypeError: undefined is not a function at $LocationProvider.$get (bower_components/angular/angular.js:11053:34) at Object.invoke (bower_components/angular/angular.js:4118:17) at bower_components/angular/angular.js:3936:37 at getService (bower_components/angular/angular.js:4077:39) at Object.invoke (bower_components/angular/angular.js:4109:13) at Object.workFn (bower_components

“Uncaught [object Object]” when running karma tests on Angular

社会主义新天地 提交于 2019-12-07 15:39:23
问题 I am fighting with this strange error when running unit tests for my application. zone.js:260 Uncaught [object Object] thrown Zone.runTask @ zone.js:260 ZoneTask.invoke @ zone.js:423 I dont know which test is failing cause the console only drop that error. It is not hapenning in my local, where the tests run whithout any problem. Before that error i was suffering the "Script error" error but I solved it with the --disable-web-security flag for ChromeHeadless. I dont know if it has something