jasmine

Jasmine test: how to call through function that is called in tested function?

半腔热情 提交于 2019-12-13 06:51:17
问题 I try to test a JavaScript function with Jasmine. It looks like this: show: function(){ this.work(); var mod = new Module(); mod.doSomething(); } I am now testing if work() is called in show() , which is no problem. But then an error occurs in mod.doSomething() . This makes my test fail although it actually passed. What can I do to prevent mod.doSomething to be called or at least executed. Is there something like callThrough() for nonused function calls? The only idea I had was to write a

How to upload karma test report to sonar?

試著忘記壹切 提交于 2019-12-13 06:09:50
问题 I have karma configured which gives me coverage report perfectly fine. It gives me in lcov format. Referring to this http://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import lcov report can be uploaded to sonar. I have installed the plugin in sonar. My project builds through ant scripts so i have added <property name="sonar.javascript.lcov.reportPath" value="/lcov.info"/> I read on some blogs that lcov needs to be corrected so that sonar can understand it. I am done with it.

ERROR in error TS2688: Cannot find type definition file for 'jest'

冷暖自知 提交于 2019-12-13 05:51:05
问题 I have an angular 6 application and I'm using karma + jasmine to run my tests. but when I run ng test I'm getting the following error: ERROR in error TS2688: Cannot find type definition file for 'jest'. Any one knows how to solve this problem? 回答1: I didn't realized that in my tsconfig.spec.jason I was using jest instead of jasmin in types node. Also, I had missing configurations. So, I changed from this: { "extends": "./tsconfig.es5.json", "compilerOptions": { "emitDecoratorMetadata": true,

test broke when changed model with interfaces to classes

十年热恋 提交于 2019-12-13 05:31:09
问题 Sorry if its a bit long but I wanted to explain myself well. I have a test for an api call im performing from my service to receive a simple json. (Karma-jasmin/angular2) this is the call from my service: @Injectable() export class MyService { constructor(private _myApiService:MyAPIService) { } public getCarsData():Observable<Car[]> { return this._myApiService.getCurrentCarData().map(res => res.carList); } } this is getCurrentCarData() : export interface CarsListResponse extends

Testing a controller that execute a service with $resource response

痞子三分冷 提交于 2019-12-13 05:25:30
问题 I have a controller that use a service, resolve a promise and then set a variable. I want to test if the variable has been set, How I do this? Service.js angular .module('myModule') .service('MyService',['$resource',function($resource){ var r = $resource('/users/:id',{id:'@id'}); this.post = function(_user){ return (new r(_user)).$save() } }]) Controller angular .module('myModule') .controller('myCtrl', ['MyService',function(MyService){ var vm = this; vm.value = 0; vm.post = function(_user){

How to test a meteor method that relies on Meteor.user()

ぃ、小莉子 提交于 2019-12-13 05:03:00
问题 I am trying to determine the best way to test my code and am running into complications from every direction I've tried. The basic code is this (though far more complex due to several layers of "triggers" that actually implement this): Client populates an object Client calls a meteor method and passes the object Meteor method uses Meteor.user() to get the current user, adds a "createdby" attribute to the object, inserts the object and then creates another object (of a different type) with

Is there any wait() function for AngularJS Jasmine test?

你说的曾经没有我的故事 提交于 2019-12-13 04:55:59
问题 I created a popup, it will open on first click and will close on second click. However, I faced problem when do testing. The second click doesn't close the popup. And I found out that the problem is because during the first click the popup haven't appeared in the screen yet, that's why the second click doesn't close the popup. So, I decide to put a delay between the clicks. Any idea on how to implement the delay? describe('Popup', function(){ it("Should close on second click", function(){

Debug Source Code while Running UnitTests

烂漫一生 提交于 2019-12-13 04:28:35
问题 I have a background as Java dev and there I could use breakpoints in my SourceCode and run UnitTests to hit them. I'm trying the same now in an Angular/Typescript environment but I can only hit breakpoints in my test code. Source Code: 1) export class SomeClass { 2) someMethod() { 3)* doit; 4) } 5) } Breakpoint not hit Test Code: 1) describe('SomeClass', () => { 2) it('test someMethod()', () => { 3) SomeClass someClass = new SomeClass(); 4)* someClass.someMethod(); 5) } 6) } Breakpoint hit My

AngularJS - Unit test for http get to JSON file

纵饮孤独 提交于 2019-12-13 04:13:07
问题 I am trying to write a unit test to test a simple factory that performs a http.get to retrieve a JSON file. The factory is called within my controller. Here's a plunker showing my http.get: http://plnkr.co/edit/xg9T5H1Kreo4lwxzRQem?p=preview Ctrl: app.controller('MainCtrl', function($scope, $http, factoryGetJSONFile) { factoryGetJSONFile.getMyData(function(data) { $scope.Addresses = data.Addresses.AddressList; $scope.People = data.Names.People; }); }); Factory: app.factory('factoryGetJSONFile

Unit testing subscribe method using jasmine in angular project

余生颓废 提交于 2019-12-13 03:37:37
问题 I'm trying to test ngOnInit() method for the component that has a subscribe method: Component: import { Component, OnInit} from '@angular/core'; import { SharedDataService } from './../services/shared-data.service'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { constructor(private sharedDataService: SharedDataService,) { } this.subscriptions = []; ngOnInit() { this.subscriptions.push