karma-jasmine

Updating the version of Jasmine used in karma-jasmine

▼魔方 西西 提交于 2019-11-29 21:20:54
Questions How can I update the version of Jasmine used when running Jasmine via Karma using the karma-jasmine plugin? Will Jasmine only get updated whenever the karma-jasmine plugin integrates a newer version of Jasmine , or can I point the karma-jasmine plugin to a newer version of Jasmine ? What version of Jasmine is installed by karma-jasmine ? Background I've installed Karma and karma-jasmine using Yeoman as follows: $ npm install -g generator-angular $ mkdir myapp && cd $_ $ yo angular Given that myapp/bower.json didn't list Jasmine as one of the Bower installed front-end packages but

mock angular service/promise in a karma/jasmine test

余生长醉 提交于 2019-11-29 21:04:30
I'm trying to write a karma/jasmine test and I would like some explanations about how mocks are working on a service which is returning a promise. I explain my situation : I have a controller in which I do the following call : mapService.getMapByUuid(mapUUID, isEditor).then(function(datas){ fillMapDatas(datas); }); function fillMapDatas(datas){ if($scope.elements === undefined){ $scope.elements = []; } //Here while debugging my unit test, 'datas' contain the promise javascript object instead //of my real reponse. debugger; var allOfThem = _.union($scope.elements, datas.elements); ... Here is

What is the difference between createspy and createspyobj

半城伤御伤魂 提交于 2019-11-29 20:53:37
I have used in my code like. return $provide.decorator('aservice', function($delegate) { $delegate.addFn = jasmine.createSpy().andReturn(true); return $delegate; }); In that what createSpy do? can i change the createSpy calls to createspyobj calls. By using createSpy, we can create one function/method mocks. Createspyobj can do multiple functions mocks. Am i right? What would be the difference. jasmine.createSpy can be used when there is no function to spy on. It will track calls and arguments like a spyOn but there is no implementation. jasmine.createSpyObj is used to create a mock that will

No provider for “framework:jasmine”! (Resolving: framework:jasmine)

冷暖自知 提交于 2019-11-29 19:13:26
When I run the command grunt I get the following warning: Running "karma:unit" (karma) task Warning: No provider for "framework:jasmine"! (Resolving: framework:jasmine) Use --force to continue. Does anybody know how to resolve this issue? I had the same error after creating a new project the yeoman angular generator (yo angular). The solution for me was adding "karma-jasmine" to the devDependencies in packages.json and running "npm install" again. npm install karma-jasmine --save-dev This solved the error message "No provider for “framework:jasmine”!" I also had to add a karma browser launcher

How to test John papa vm.model unit testing with jasmine?

别来无恙 提交于 2019-11-29 16:34:00
问题 I use John papa angular style guide my controller looks like: following the style John papa style controller style guide: function testController() { var vm = this; vm.model = { name: "controllerAs vm test" }; } My testing code looks like: describe('Controller: testController', function () { beforeEach(module('myApp')); var testController; beforeEach(inject(function ($controller) { scope = {}; testController = $controller('testController', { }); })); it('should have vm.model defined and

@ngrx/effects: testing an effect returns empty()

风格不统一 提交于 2019-11-29 15:44:44
I am using @ngrx/effects 4.1.1. I have an effect that returns an empty observable like this: @Effect() showDialog$: Observable<Action> = this .actions$ .ofType( ActionTypes.DIALOG_SHOW ) .map( ( action: DialogAction ) => action.payload ) .switchMap( payload => { this.dialogsService.showDialog( payload.className ); return empty(); } ); I am trying to write a unit test following these guidelines that will test that the effect yields an empty observable. I have this: describe( 'DialogEffects', () => { let effects: DialogEffects; let actions: Observable<any>; const mockDialogService = { showDialog

Cannot read property '_getPortal' of undefined in ionic 2 Unit testing

泪湿孤枕 提交于 2019-11-29 14:53:38
I am a beginner to ionic 2 unit testing. I followed angular 2 documentation ( https://angular.io/docs/ts/latest/guide/testing.html ) to test my ionic 2 application with karma and jasmine. But now I am stuck in an error called 'Cannot read property '_getPortal' of undefined' here is my LocationSearchModal.ts file import { Component } from '@angular/core'; import { NavController, ViewController } from 'ionic-angular'; import { Location } from '../../services/domain/Location'; import { LocationService } from '../../services/LocationService'; import { LoadingController } from 'ionic-angular';

Test component with “declare var”

喜你入骨 提交于 2019-11-29 14:18:11
In my angular2 app I have js file "connection.conf.js" with var: var appTypeConf = "example-app"; Component uses the variable from "connection.conf.js": declare var appTypeConf: string; export class Component { public appType = appTypeConf; } it works corectly in my app, but when I test application with karma, I receive a error: ReferenceError: Can't find variable: appTypeConf (line 9) How to corectly declare a variable in the component spec file? I found the solution, I had to add connection.conf.js path to files array in karma.conf.js var files = [ // *** 'app/connection.conf.js' ] 来源: https

Firebase App named '[DEFAULT]' already exists (app/duplicate-app)

倖福魔咒の 提交于 2019-11-29 13:09:58
Hi I am trying to unit test while developing a simple web with AngularJS + Firebase, but I have a problem defining the spec and trying the test runner myProject/test/spec/main.js : describe('Controller: MainCtrl', function() { var MainCtrl, scope beforeEach(module('MainApp')); beforeEach(inject(function ($controller, $rootScope) { scope = $rootScope.$new(); MainCtrl = $controller('MainCtrl', { $scope: scope }) })); it('should....',function(){ expect(true).toBe(true) }) it('should2....',function(){ expect(false).toBe(false) }) }); result: PhantomJS 2.1.1 (Mac OS X 0.0.0) Controller: MainCtrl

Get json file for karma unit test

倖福魔咒の 提交于 2019-11-29 12:35:45
I want to get a JSON file in my unit test because I need to have it for my tests but I dont know how I can include the file I run my test with karma and Jasmine. And my project is created with Angular 2. The name of my JSON file is 'www/assets/mocks/emptyCalendarData.JSON' . Does someone know how I can include a JSON file into a spec file? Thanks UPDATE I tried to use HTTP get but then I got a system let calendarData: Calendar; http.get('www/assets/mocks/emptyCalendarData.json') .map(res => res.json()) .subscribe( data => calendarData = data, err => console.log(JSON.stringify(err)) ); Then I