jasmine

How to use scope variables with the “Controller as” syntax in Jasmine?

荒凉一梦 提交于 2019-12-05 09:10:09
问题 I'm using jasmine for angularJS testing. In my views, I'm using the "Controller as" syntax: <div ng-controller="configCtrl as config"> <div> {{ config.status }} </div> </div> How can I use these "scope" variables in jasmine? What does the "Controller as" refer to? My test looks like following: describe('ConfigCtrl', function(){ var scope; beforeEach(angular.mock.module('busybee')); beforeEach(angular.mock.inject(function($rootScope){ scope = $rootScope.$new(); $controller('configCtrl', {

Browser page keeps refreshing when testing Backbone views with Jasmine

强颜欢笑 提交于 2019-12-05 08:59:39
Running the following Jasmine test(1), the test is successfully performed but I face the recursive loading of the main test page. Here is my test (1) and here the module on which I am running the test (2): Any ideas? How can I fix the issue? P.S.: The issue regard just Chrome and Safari Browser. Here is an example: jsfiddle.net/shioyama/EXvZY (1) describe('When Submit button handler fired', function () { beforeEach(function () { spyOn(MyView.prototype, 'submitForm'); this.view = new MyView(); this.view.render(); this.view.$el.find('form').submit(); }); it('submitForm should be called',

Protractor E2E Testing Error : Object [object Object] has no method 'getWindowHandle'

随声附和 提交于 2019-12-05 08:34:11
I am trying to check the pop up for facebook login opening on click of button . Error : Object [object Object] has no method 'getWindowHandle'. Code Snippet generating error : describe('Tests', function() { var ptor; var handlePromise; var util = require('util'); beforeEach(function() { ptor = protractor.getInstance(); handlePromise = ptor.getAllWindowHandles(); var handlesDone = false; ptor.get('/SiteB_Upgrade_Device/app/index.html#/Recommendations#page'); ptor.findElement(by.id('fb')).click(); ptor.ignoreSynchronization = true; }); describe('login', function() { return it('should switch to

Force-failing a Jasmine test

独自空忆成欢 提交于 2019-12-05 08:20:55
问题 If I have code in a test that should never be reached (for example the fail clause of a promise sequence), how can I force-fail the test? I use something like expect(true).toBe(false); but this is not pretty. The alternative is waiting for the test to timeout, which I want to avoid (because it is slow). 回答1: Jasmine provides a global method fail() , which can be used inside spec blocks it() and also allows to use custom error message: it('should finish successfully', function (done) {

Trying to spy (Jasmine) on Array.prototype methods causes stack overflow

狂风中的少年 提交于 2019-12-05 08:06:42
This is pretty odd. Using the testem runner with jasmine2 and the following spec executes (though it correctly flags that there are no expectations): describe('Spying on array.prototype methods', function(){ it('should work this way', function(){ spyOn( Array.prototype, 'push' ).and.callThrough(); // expect(1).toBe(1); }); }); However, add an expect (any expect !) and it causes the stack to overflow with the following message in the testem console: RangeError: Maximum call stack size exceeded. at http://localhost:7357/testem/jasmine2.js, line 980 The html report page gets up to the spec and

How do you spy on AngularJS's $timeout with Jasmine?

て烟熏妆下的殇ゞ 提交于 2019-12-05 07:55:11
I am trying to spy on $timeout so that I can verify that it has not been called. Specifically, my production code (see below) calls $timeout as a function, not an object: $timeout(function() { ... }) and not $timeout.cancel() // for instance Jasmine, however, requires an object to be spied upon, like this: spyOn(someObject, '$timeout') I don't know what 'someObject' would be though. I am using Angular mocks, if that makes any difference. Edit: The relevant production code I'm trying to test looks like this: EventHandler.prototype._updateDurationInOneSecondOn = function (call) { var _this =

Error: Unexpected request: GET views/partials/* for a nested directive even when using html2js in karma/jasmine unit test

自闭症网瘾萝莉.ら 提交于 2019-12-05 07:54:18
I am using Karma and Jasmine for unit testing for my angularjs application. I have a directive's(say Directive A) template in which another directive(say Directive B) is getting rendered, although it is working fine in application but test case fails to render the Directive B's template. Following is the error I get :- Error: Unexpected request: GET views/partials/directiveb.html Expected GET https://my-sandbox.app.com/123456 Below is the directive A's code :- angular.module('myApp') .directive('directiveA', function (myservices, myOtherServices) { return { controller: function(){ /* ...

d3 transition in unit-testing

泄露秘密 提交于 2019-12-05 07:52:43
I have an chart built by d3 and which appears with transitions and I need to test chart when all transitions have ended. I use jasmine for unit-testing. How to do it? I find method d3.timer.flush() , but it skips only first frame, but I want to skip all animations and see an final result right now and make some assertions on it. You can execute transitions synchronously directly to their final state with one call to D3's timer flush if you mock out its timestamp determination during the flush like so: An alternative to mocking out transitions is executing them synchronously directly to their

$browser.$$checkUrlChange is undefined in a jasmine test

孤人 提交于 2019-12-05 07:43:36
I have the following test: it('should maintain a bind between the data at the $scope to the data at the ingredientsService', function(){ $scope.addFilters('val1', $scope.customFiltersData, 'filter1'); $scope.$digest(); expect($scope.customFiltersData).toEqual(ingredientsService.filters()); }); I get the following error: TypeError: undefined is not a function at Scope.$digest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12502:17) at null.<anonymous> (/home/oleg/dev/vita-webapp-new/test/spec/controllers/customfilters.js:92:20) When debugging I saw that $browser.$

TypeError: 'undefined' is not an object (evaluating 'currentSpec.queue.running')

≡放荡痞女 提交于 2019-12-05 07:42:04
问题 I am using karma + jasmine. Now thatI have tried one way of mocking a dependent factory I get this error: TypeError: 'undefined' is not an object (evaluating 'currentSpec.queue.running') at C:/test/test/client/app/bower_components/angular-mocks/angular-mocks.js:1924 at C:/test/test/client/app/bower_components/angular-mocks/angular-mocks.js:1979 at C:/test/test/client/test/spec/services/lessonplannerfactory.js:31 at C:/test/test/client/node_modules/karma-jasmine/lib/boot.js:117 at C:/test/test