jasmine

Chutzpah coverage result smaller than 100% (due to private methods?)

时光怂恿深爱的人放手 提交于 2020-01-14 02:08:08
问题 I use Chutzpah to test my JavaScript test coverage. Here is an example for the coverage result when I run a single test file referenceFigureEdit.spec.js : I would expect the coverage to be 100% but it is only 91.07%. Clicking on the first line I can inspect my tested code in detail. Lines that are "not covered by the test" are highlighted: Question A : How can I tell Chutzpah that those methods have actually been executed or tell Chutzpah to not include those lines in the coverage result? Are

Mock AngularFireAuth When Unit Testing an Angular Service

吃可爱长大的小学妹 提交于 2020-01-13 18:12:46
问题 I have an authService which when instantiated subscribes to AngularFireAuth 's Observable authState and sets the services' internal (private) property authState . So I can unit test authService I highjack the services' internal authState with Reflect.get/set in my test specs so I can control its value. The problem is of course authService is still subscribing to AngularFireAuth 's Observable authState during its instantiation and I don't want, nor need it to. I presume I need to mock out

Module not found error in AngularJS unit test

随声附和 提交于 2020-01-13 13:52:44
问题 I'm trying a very simple test with Karma/Jasmine, to unit test my AngularJS app. This seems to work beforeEach( module('myApp') ); it('should blah', function () { expect(true).toBe(true); }); while this doesnt beforeEach( function () { module('myApp') } ); it('should blah', function () { expect(true).toBe(true); }); I want to be able to do other stuff beforeEach test suite, but it's not giving me any meaningful errors to be able to debug it, the only one I see is TypeError: 'undefined' is not

Module not found error in AngularJS unit test

匆匆过客 提交于 2020-01-13 13:52:25
问题 I'm trying a very simple test with Karma/Jasmine, to unit test my AngularJS app. This seems to work beforeEach( module('myApp') ); it('should blah', function () { expect(true).toBe(true); }); while this doesnt beforeEach( function () { module('myApp') } ); it('should blah', function () { expect(true).toBe(true); }); I want to be able to do other stuff beforeEach test suite, but it's not giving me any meaningful errors to be able to debug it, the only one I see is TypeError: 'undefined' is not

Protractor closing current tab

为君一笑 提交于 2020-01-13 13:12:34
问题 I have a non-angular page where I need to click on 2 links. When clicking on one of the link that automatically opens in a new tab. Now I switch to new tab and set the browser.ignoreSynchronization = false because the newly opened tab is a angular window; and call one of my test. Once verified. I want to close the current tab and go back to the non-angular page to click on link #2 which would again open in a new tab. I tried window.close but i am getting window is undefined. I used browser

How to mock Blob and Click() in jasmine Specs in angular js

谁说胖子不能爱 提交于 2020-01-13 11:42:48
问题 How to write Jasmine specs for Blob and Click() event. Every time I am running Specs its downloading file. Can I mock this (and browser also). Thanks var csvFile = "a,b,c",filename="abc.csv"; var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' }); if (navigator.msSaveBlob) { // IE 10+ navigator.msSaveBlob(blob, filename); } else { var link = document.createElement("a"); if (link.download !== undefined) { // feature detection // Browsers that support HTML5 download attribute var

How to mock Blob and Click() in jasmine Specs in angular js

删除回忆录丶 提交于 2020-01-13 11:42:48
问题 How to write Jasmine specs for Blob and Click() event. Every time I am running Specs its downloading file. Can I mock this (and browser also). Thanks var csvFile = "a,b,c",filename="abc.csv"; var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' }); if (navigator.msSaveBlob) { // IE 10+ navigator.msSaveBlob(blob, filename); } else { var link = document.createElement("a"); if (link.download !== undefined) { // feature detection // Browsers that support HTML5 download attribute var

Angular2 RC.1 - Inject Router into unit test

廉价感情. 提交于 2020-01-13 10:47:27
问题 I'm writing my ng2 tests, and I'm running into some trouble injecting Router into my component for my test. The constructor for my component only takes one argument-- private router: Router . But, when I run my test case, I'm getting an error while it's trying to inject the Router. What am I doing wrong? Can anyone provide a working example? I'm using angular2-RC.1 Here's the error I'm getting: No provider for ComponentResolver! (Router -> ComponentResolver) Here's my test: import {describe,

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

戏子无情 提交于 2020-01-13 09:29:47
问题 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')

Do I need to unsubscribe from subscriptions in my unit tests?

纵饮孤独 提交于 2020-01-13 08:24:39
问题 If I have a test such as the following: it('should return some observable', async(() => { mockBackend.connections.subscribe((mockConnection: MockConnection) => { const responseOptions = new ResponseOptions({ body: JSON.stringify(/* some response */) }); mockConnection.mockRespond(new Response(responseOptions)); }); service.getSomeObservable() .subscribe(result => { expect(result).toBe(/* expected response */); }); })); Do I need to unsubscribe from the subscription in an afterEach or afterAll