karma-jasmine

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

我的未来我决定 提交于 2019-12-18 10:01:04
问题 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? 回答1: 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

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

怎甘沉沦 提交于 2019-12-18 08:50:02
问题 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 {

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

有些话、适合烂在心里 提交于 2019-12-18 08:46:36
问题 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', (

Test component with “declare var”

人盡茶涼 提交于 2019-12-18 08:44:07
问题 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? 回答1: I found the solution, I had to add

Is jasmine supposed to execute specs in the order they are declared or in a random order?

亡梦爱人 提交于 2019-12-18 05:28:26
问题 un-comment the last spec. All hell breaks loose... why? describe('test', function() { var index = 1; it('test 1', function() { expect(index).toBe(1); index++; }); it('test 2', function() { expect(index).toBe(2); index++; }); it('test 3', function() { expect(index).toBe(3); index++; }); it('test 4', function() { expect(index).toBe(4); index++; }); it('test 5', function() { expect(index).toBe(5); index++; }); it('test 6', function() { expect(index).toBe(6); index++; }); it('test 7', function()

Karma unit testing: Module name “react” has not been loaded yet for context: _. Use require([])

末鹿安然 提交于 2019-12-17 21:11:46
问题 I am trying to set up the unit testing framework for react. While doing so, the following error has occurred. I have searched all over the internet with no solution that is working. below are the errors shown and code/packages that I am using. debug error 04 03 2016 04:48:46.340:DEBUG [phantomjs.launcher]: Error: Module name "react" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded 04 03 2016 04:48:46.341:DEBUG [phantomjs.launcher]: http:/

Angular 2 RC5 Testing Promises in ngOnInit Not Working

只愿长相守 提交于 2019-12-17 20:29:32
问题 I am trying to test a structural directive named MyDirective with Jasmine. The Angular version used is RC5. // Part of the MyDirective class @Directive({selector: '[myDirective]'}) export class MyDirective { constructor(protected templateRef: TemplateRef<any>, protected viewContainer: ViewContainerRef, protected myService: MyService) { } ngOnInit() { this.myService.getData() .then((data) => { if (!MyService.isValid(data)) { this.viewContainer.createEmbeddedView(this.templateRef); } else {

Karma: Running a single test file from command line

[亡魂溺海] 提交于 2019-12-17 17:33:54
问题 So, I've been looking all over for this, found "similar" answers here, but not exactly what I want. Right now if I want to test a single file with karma, I need to do fit() , fdescribe() on the file in question... However, what I do want is to be able to just call karma, with the config file, and direct it to a specific file, so I don't need to modify the file at all, ie: karma run --conf karma.conf.js --file /path/to/specific/test_file.js is it possible to do this? Or with any helper? (using

What is the best practice to test private methods in Angular 2 / Typescript

空扰寡人 提交于 2019-12-14 03:24:00
问题 I've created Angular 5 project and writing unit tests using Karma, Jasmine. I don't like the idea of making all methods public only for accessing from tests. export class AppComponent { mainMenu: any[]; constructor( private menuService: MenuService ) {} ngOnInit(): void { this.initTable(); this.initMenu(); } private initTable(): void { // ... initializes array for table } private initMenu(): void { this.menuService.getMainMenu() .subscribe(data => this.mainMenu = data); } } initTable and

Cannot read property “loadListing” of Undefined -Karma Jasmine

拟墨画扇 提交于 2019-12-13 21:11:46
问题 This is my test case for checking whether the function is defined or not in the controller Function: $scope.loadData = ()=> { LoadService.loadListing().then(function (responseData) { alert("Success"); } Test Case: it('should have loadMeetings function', function () { expect(angular.isFunction(scope.loadData )).toBe(true); }); The Error : TypeError: Cannot read property 'loadListing' of undefined at Scope.MyCtrl.$scope.loadData 来源: https://stackoverflow.com/questions/27740395/cannot-read