jasmine

Jasmine test for AngularJS $locationChangeSuccess

▼魔方 西西 提交于 2019-12-11 18:29:03
问题 How would I write a test for this following piece of code? $scope.$on('$locationChangeSuccess', function () { $(".modal-backdrop").removeClass('modal-backdrop'); }); 回答1: The following should work: beforeEach(function() { $('body').append('<div id="test" class="modal-backdrop"/>'); }); afterEach(function() { $('#test').remove(); }); it('should remove the classname on $locationChangeSuccess', function() { spyOn($scope, '$on').and.callThrough(); $scope.$broadcast('$locationChangeSuccess');

why “[web-server]: 404: /absoluteC” when running karma

跟風遠走 提交于 2019-12-11 17:36:27
问题 I found several similar question but none of the suggestions fixed my issue. Basically they are suggesting add some dependency (I am using only native webcomponents so it doesn't appliy to my case) or check the path. I checked carefully and the path is 100% correct. I found a bit strange that the warnning message shows absolute before the real path. BTW, the path is really coorect. Whole code github Karma.conf.js module.exports = function(config) { config.set({ frameworks: ["jasmine"], files:

How to test callback function with Jasmine

天大地大妈咪最大 提交于 2019-12-11 17:32:40
问题 Given the function with callback as follows: myfunction('some value', function(){ //do something... }) How can I cover and test it using Jasmine ? It never enters in the flow inside the function(){... callback. Thanks 回答1: In cases like this, there are (at least) two unit tests that you need to create: a test for myFunction a test for the callback So it might look something like this: it('should test myFunction', () => { let spy = jasmine.createSpy(); let result = myFunction(spy); expect(spy)

Protractor - Unable to access element due to fixed Top navigation bar

给你一囗甜甜゛ 提交于 2019-12-11 17:08:52
问题 I'm facing the following issue in protractor with jasmine Click/mouse hover not working because of fixed top navigation bar in my application. I need to click/perform mouse hover on a web page. Unfortunately that element is displaying behind that fixed navigation bar. So scroll till element present & click by x & y coordinates are not working. My dependencies are : protractor version 5.2.2 node 8.9.3 selenium standalone 3.13 chrome driver-2.40 chromebrowser v67 OS- Windows 10 Thanks in

Testing event chains and module.run() in Angular + Jasmine

[亡魂溺海] 提交于 2019-12-11 16:33:17
问题 I am trying to test a module that has the following code: angular.module('angularEnterpriseAuthorization').run(['$rootScope', '$state', 'AppConfig', function($rootScope, $state, AppConfig) { // On every time the user changes state check to see if the user has permissions to go to the new state $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) { // If the state is not one of the public states as defined in the modules config if (AppConfig

Angular testing Service method with window.location.replace

点点圈 提交于 2019-12-11 15:31:43
问题 In my Angular 4 application, I need to test a method of a Service which at some point it calls a private method of the same service having: window.location.replace(url); When the test reach that line, the karma-runner browser gets redirected to the url which of course is not what I want. If I try to spy it, I get: Error: <spyOn> : replace is not declared writable or has no setter How can I correctly test my method? 回答1: location object is read-only property, and its properties are read-only

Jasmine/Karma testing Angular 5 HTTP responses

梦想的初衷 提交于 2019-12-11 15:15:14
问题 I'm totally new to TDD and I'm trying to debug a big Angular 5 application we're working in, at the company. The app is working well, but now I have to implement tests, and I'm learning this stuff while I create the most basic and starter ones. I wrote this stuff already for the main module, just for trying this tooling: describe('AppComponent', () => { let httpClientSpy: { get: jasmine.Spy } let dataReq: DataRequester; let queryBuilder: PanelQueryBuilder; let query: DataQuery; beforeEach

Protractor tests , Jasmine and asynchronous solution

纵饮孤独 提交于 2019-12-11 14:25:57
问题 I using in my work protractor with jasmine . What found annoying and disturbing is ways I have to write always tests. I really don't like to do this waitsFor for promise from getCssValue. Can someone can show me better solution for asynchronous tests then this. At moment using Jasmine 2.0" describe('And I see a “Burger Menu” option on the Header section', function () { it('And the Left Hand Navigation is not visible When I access a Burger menu option on the ' + 'Header section Then I want to

Testing a select tag, angular js and jasmine

心不动则不痛 提交于 2019-12-11 14:02:29
问题 I have this select box which filters when I change another select. Trying to write a e2e test. This is my markup: <select id="inputPipe" ng-model="selectedPipe" ng-options="p.title_en for p in pipes"></select> <select id="inputSize" ng-model="selectedSize" ng-options="s.nominalsize for s in sizesFromPipes"></select> So when I change the first select the second gets filtered. This is my e2e test select('selectedPipe').option('Steel'); Then I'm not sure how to continue. This a pseudo code:

Getting a 404 on angular2/testing

瘦欲@ 提交于 2019-12-11 13:53:53
问题 I am getting a 404 on angular2/testing as soon as i insert this line into my spec file. import { iit, it, inject, injectAsync, beforeEachProviders, fakeAsync, tick } from 'angular2/testing'; This is my code inside body tag in user-tests.html <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="node_modules/angular2/bundles/angular2.dev.js"></script> <script src="node_modules/angular2/bundles/http.dev.js"></script> <script src="node_modules/angular2/bundles/router.dev