karma-jasmine

Testing ngOnChanges lifecycle hook in Angular 2

送分小仙女□ 提交于 2019-12-29 05:41:35
问题 Given the following code I try to test the ngOnChanges lifecycle hook of Angular2: import { it, inject, fdescribe, beforeEachProviders, } from '@angular/core/testing'; import {TestComponentBuilder} from '@angular/compiler/testing'; import {Component, OnChanges, Input} from '@angular/core'; @Component({ selector: 'test', template: `<p>{{value}}</p>`, }) export class TestComponent implements OnChanges { @Input() value: string; ngOnChanges(changes: {}): any { // should be called } } fdescribe(

Providing/Injecting third party service to component while angular component unit testing

拜拜、爱过 提交于 2019-12-25 17:04:37
问题 I have just started with Angular Unit testing, LoginComponent is dependent on third party module's (Fuse) service FuseConfigService . Here is how FuseConfigService look like @Injectable({ providedIn: 'root' }) export class FuseConfigService { private _configSubject: BehaviorSubject<any>; private readonly _defaultConfig: any; /** * Constructor * * @param {Platform} _platform * @param {Router} _router * @param _config */ constructor( private _platform: Platform, private _router: Router, @Inject

Can't bind to 'thick' since it isn't a known property of 'ng-progress'

自闭症网瘾萝莉.ら 提交于 2019-12-25 09:29:02
问题 I am trying to use this plugin to my app: https://github.com/MurhafSousli/ngx-progressbar#user-content-automagic-loading-bar Its working fine, but when I run test on it, it fails with error: Can't bind to 'thick' since it isn't a known property of 'ng-progress'. app.module.ts import { NgProgressCustomBrowserXhr, NgProgressModule } from 'ngx-progressbar'; @NgModule({ declarations: [ AppComponent ], imports: [ NgProgressModule ], providers: [ { provide: BrowserXhr, useClass:

Karma Angular - Cannot Find Name 'X'

左心房为你撑大大i 提交于 2019-12-25 08:51:42
问题 I'm getting a load of errors when I run Karma Start in my angular project. All the errors say: 'Cannot find name Blob', 'Cannot Find name KeyboardEvent', 'Cannot find name HTMLElement', etc. my tsconfig.json: { "compileOnSave": false, "compilerOptions": { "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "es2016", "dom" ], "typeRoots": [ "./node_modules/@types/" ], "types": [

unit testing two service which are in different module with jasmine

痴心易碎 提交于 2019-12-25 08:14:25
问题 I have written some service in angular. Check this PLUNKER. Injecting CommonService, $rootRouter, ModalService in RouteService . Mind the module : CommonService is in mysampleapp.core RouteService is in mysampleapp Also when I try to do this beforeEach(module('mysampleapp.core')); beforeEach(module('mysampleapp')); It gives me some weird ReferenceError: Can't find variable: Map (line 2166) error. Do i need to do the above or am doing it in wrong way?? I am stuck with unit testing RouteService

Integrating javascripts unit tests code coverage in MSBuild

青春壹個敷衍的年華 提交于 2019-12-25 04:22:23
问题 I am using Jasmine and Karma for writing unit tests and code coverage. I have created the tasks using Gulp and running them through task runner explorer in VS 2015 update 3. var gulp = require("gulp"); var Server = require('karma').Server; var remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul'); gulp.task('unit-tests', function (done) { new Server({ configFile: __dirname + '/karma.conf.js' }, done).start(); }); gulp.task('code-coverage', function () { return gulp.src('_reports

$ionicPopup.show buttons onTap function not getting coverage in Angular Jasmine Unit Test

走远了吗. 提交于 2019-12-25 01:53:08
问题 When I call the outOfMvp() function in my unit test spec file, everything inside the function is getting coverage except for the onTap function. I was wondering how to get coverage in my unit test for the button's onTap function which is in a JSON object being passed in $ionicPopup.show() method? Here is the function in the js file: function outOfMvp(data) { environmentConfig.isScanDataReadValid = false; popup = $ionicPopup.show({ title: kioskConstants.POPUP_WORDING.OUT_OF_MVP_RETURN.title,

How can i coverage a promise response with Jasmine and Karma

狂风中的少年 提交于 2019-12-25 01:12:10
问题 I have a function that returns and treats a promise, I need to cover the return that is inside then but I don't know how I can do this, I'm currently trying as follows: confirmRemoveUser(user: IUser) { this.modalService .open('Confirma a exclusão do usuário selecionado?', { titleText: 'Confirmando exclusão', confirmButtonText: 'Sim', cancelButtonText: 'Cancelar', closeButtonText: 'Fechar', buttonType: 'danger' }) .result.then( (result: BentoModalConfirmationCloseReason) => { if (result ===

Angular & StompJS provokes Karma test load failure

╄→尐↘猪︶ㄣ 提交于 2019-12-24 19:14:50
问题 We are using Angular 5.2.0 and we recently added StompJS 2.2.3 for WS features. "dependencies": { "@angular/animations": "^5.2.0", "@angular/common": "^5.2.0", "@angular/compiler": "^5.2.0", "@angular/core": "^5.2.0", "@angular/forms": "^5.2.0", "@angular/http": "^5.2.0", "@angular/platform-browser": "^5.2.0", "@angular/platform-browser-dynamic": "^5.2.0", "@angular/router": "^5.2.0", "...", "stompjs": "^2.3.3", }, However, since the addition, Karma tests won't load with the error : ERROR in

Angular6: How can I generate a default angular.json file from command line [duplicate]

不想你离开。 提交于 2019-12-24 19:08:14
问题 This question already has answers here : How to generate .angular-cli.json file in Angular Cli? (9 answers) Closed last year . I create a new module using angular 6, that will serve as a package to use in another project. Now, I'm trying to configure the karma and jasmine so I could create unit tests on it. The problem is that I found out that the project does not have any angular.json file. It is possible to generate a default angular.json file from the command line? 回答1: Your best bet is to