Questions tagged [karma-jasmine]

0

votes
0

answer
2

Views

Check if there is a plugin with Karma

I'm trying to do a unit test to check if the Calendar (https://ionicframework.com/docs/v3/native/calendar/) plugin has been properly included. Here's the code: describe('Calendar', function() { it('should exist', function() { expect(cordova.plugins.calendar).toBeDefined(); }); }); When running the k...
0

votes
0

answer
9

Views

Karma, Angular 7, & FontAwesome issue Can't bind to 'icon' since it isn't a known property of 'fa-icon'

Can't bind to 'icon' since it isn't a known property of 'fa-icon'. When trying to run this test in people.component.spec.ts import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { PeopleComponent } from './people.component'; describe('PeopleComponent Unit Test', () => { le...
John Peters
1

votes
2

answer
1.5k

Views

Ionic 2 : Test with jasmine and karma error 'ng test'

I try to follow this tutorial : http://lathonez.com/2017/ionic-2-unit-testing/ And when I run 'ng test' I have this error : C:\xampp\htdocs\AppFineMobile>ng test 27 03 2017 11:55:00.556:ERROR [preprocess]: Can not load 'angular-cli', it is not registered! Perhaps you are missing some plugin? No pr...
V. Pivet
1

votes
0

answer
16

Views

AngularJS unit testing Karma - unknown provider

I am trying to set up unit tests on our legacy AngularJS app. I am using the standard karma along with angular-mock to set up the tests cases. But I am getting issues with Unknown provider when I am trying to inject some services and factory. My karma.conf looks something like this (I have removed a...
Tushar Chutani
1

votes
2

answer
1.3k

Views

How can I resolve Angular unit test error: “An error was thrown in afterAll\n[object ErrorEvent] thrown”

When I run ng test command in my angular project has error, it gives an error like that 10% building modules 1/1 modules 0 active04 12 2018 11:29:43.408:WARN [karma]: No captured browser, open http://localhost:9876/ 04 12 2018 11:29:43.414:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:...
Samet ÇELİKBIÇAK
1

votes
1

answer
63

Views

How to unit test return value of function - Angular (Jasmine/Karma)

I am wondering if there is a way to correctly test the return value of a function in Angular. I want to essential test the return value to be true for one test and write another to test the opposite scenario. Ts component: get() { if (this.object == undefined) { return true; } else { return false;...
thenolin
1

votes
2

answer
743

Views

Slow Karma Unit Tests

I wrote unit tests for a small reach application using Jasmine and Karma.And Karma is running slow for these tests. This is my karma config: var unitTestReportOutputDir = 'unit-test-report'; module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'], reporters: ['dots'],...
zfranciscus
1

votes
0

answer
50

Views

How to test AngularJS controller using Karma-Jasmine

I am trying to use Jasmine and karma to set up unit tests like explained here, in my already developed Angularjs application. I created a simple test file for my controller like this: describe('controller test', function() { beforeEach(module('ipaApp')); var $controller, $rootScope; beforeEach(injec...
Manoj Suthar
1

votes
0

answer
638

Views

Scrolling test with Jasmine

I am trying to test an angular Directive that do something on scroll, with Jasmine and Angular. Here is the directive code: @Directive({ selector: '[dfScroller]' }) export class ScrollerDirective { @select(['module', 'sessionTimeout', 'showTimeoutWarning']) readonly showTimeoutWarning$: Observable;...
Jean-Baptiste
1

votes
1

answer
40

Views

Can see function from javascript file but not variables

My directory structure is as follows: src |--> js |--> more js files in nested folders test |--> spec |--> js test files If within one of my js tests in spec, if I try and call a function from a js file within my nested src directories, I can call the function fine. However, if I try and call a vari...
dahui
1

votes
0

answer
90

Views

Testing http intercetpor in angular2

I'm testing an angular2 HTTP interceptor and I get the following error: Error: Expected no open requests, found 1: GET /web-service it('check if request path...', inject([HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => { http.get('/web-service').subscribe(...
eugen sunic
1

votes
1

answer
493

Views

spyOn service / component Angular2

I'm trying to implement unit test with service. I'd like some clarification on why this isn't working. setUp for my spec class. beforeEach(() => { fixture = TestBed.createComponent(testComp); service = fixture.debugElement.injector.get(TestService); }); it('mockService', () => { spyOn(service, 'tes...
Kenny
1

votes
0

answer
112

Views

Karma not running any unit test cases

I am trying to set up Karma for a small demo project. The problem is that Karma is not executing any test cases. My project has only two .js files: app/js/app.js and test/spec/app.spec.js My karma config file is as follows: module.exports = function(config) { config.set({ basePath: '', frameworks: [...
aryan87
1

votes
1

answer
43

Views

Include an angular module in all.spec files via karma

I have an angular module that has some angular configuration that I want all tests to have before running. I could go in all the files and include that module via angular.mock.module but I was wondering if I could do it via karma somehow.
fur866
1

votes
0

answer
207

Views

jasmine html loader is not loading in angular 4 webpack

I am trying to unit test my angular app.as am new to this karama test i am trying to karma,jasmine and protractor..i ve downloaded and all karma dependencies.i am using angular webpack version in visual studio 2017.i am facing some issues like 1.karma html loader is not loading,only i can see karma...
baby
1

votes
1

answer
39

Views

Error: Error in :0:0 caused by: Function expected

I want to mock this._configuration.setLocalStorage_SingleValue() method ngOnInit() { // this.getErrorLog(); this._configuration.setLocalStorage_SingleValue('previousUrl', window.location.href);// throw error this.pageinationcount = this._configuration.getLocalStorage_SingleValue('previousUrl'); }...
Ramesh Rajendran
1

votes
0

answer
238

Views

How to test the output of an NgForm function in angular

I want to test the result from submitting my form in angular but I am not sure what to expect. I have created my mock data and created a spy with with jasmine but I write the expect. I know it returns an Observable but how do I test that? My template const testForm = { value: { address: { billing_ad...
Arthur Decker
1

votes
0

answer
157

Views

How to test selected option in md-select

I want to test available option in view test but I can not see the selected option in md-select, I see placeHolder text. Test's error message like this 'Expected 'Country ' to be 'Turkey', 'selected country must be loaded correctly in view'.' view: {{ country.name}} test: it('customer should edit',...
Bedirhan Tepebaşı
1

votes
0

answer
54

Views

AngularJS Jasmine: mocking ngModule with dependencies

So in my project I'm using only one module everywhere. Here is how it looks: angular .module('moduleToMock', [ 'ngAnimate', 'ngAria', 'ngMessages', 'ngRoute', 'ngMaterial', 'md.data.table', 'textAngular', 'ui.utils.masks', 'mp.colorPicker', 'mdPickers', 'ngCookies', 'ngIdle', 'toastr', 'ui.bootstrap...
Lunin Roman
1

votes
1

answer
347

Views

how to unit test Angularfire2(version 5) auth service with google provider login

I'm trying to set up unit tests for a sample Angular5 app using AngularFire2 (version5) google provider login, My auth service is fairly simple and it looks like this: let authState = null; let mockAngularFireAuth: any = {authState: Observable.of(authState)}; @Injectable() export class AuthService {...
lanchana gupta
1

votes
0

answer
73

Views

$digest already in progress in unit test jasmin

I have controller like below (function () { 'use strict'; angular.module('fccui') .controller('OfferPricingCtrl', ['$rootScope','$scope', '$mdDialog', 'Constants', '$localStorage', '$log','rest','$q','catalog', function ($rootScope,$scope, $mdDialog, Constants, $localStorage, $log,REST,$q,catalog) {...
nborpe
1

votes
0

answer
37

Views

angularjs: ng-bind variable updated in karma unit test, but view not updated

html: controller.js $scope.func = function _func(name) { let w = angular.element('#id').width(); console.log(w); return w; } test.js describe('test', () => { // prepare scope ... $scope.node.name = 'testtesttestname'; let element = angular.element('#id'); angular.element(document).find('body').appen...
L.L
1

votes
0

answer
165

Views

Trigger TouchMove event in Typescript

I am writing some unit tests for an Angular 5 application and have run into an issue trying to trigger a TouchMove event manually. I was able to get this to work for a simulated mouse event using document.dispatchEvent(new MouseEvent('mousemove', { clientX: 100 })); but if I try writing document.dis...
Paul Freedman
1

votes
0

answer
52

Views

Trouble with MdDialogRef from Angular Material testing angular app

Would anyone help me please! I'm trying to test my LoginComponent that uses Angular Material, I already use MdDialogRef on production code and this is my test class so far, where I just want to fill all dependencies to make it run: import { async, ComponentFixture, TestBed } from '@angular/core/tes...
Francisco Sales
1

votes
1

answer
73

Views

AngularJS - $emit test case in Karma

I'm new and doing my first Karma testing and have referred this post for $emit test case. I have some trouble understanding the concept. This is my code: ctrl.toggleUserMode = function(pUserId, pUserName, userModeFlag) { $scope.$emit('userModeToggleEvent', userModeFlag); } Sorry If my question see...
Pavan
1

votes
0

answer
71

Views

Angular4 - Karma-Jessie; How to cover a response in ngOnInit?

Scenario Here is the code of the karma-test: it('ngOnInit', inject([NuarKeySignatureService], (service: NuarKeySignatureService) => { const challenge = new SignatureResultPositionChallenge(); challenge.challenge = ['1', '2', '3', '4']; service.setChallengeEvent(challenge); fixture.detectChanges(); s...
JoseJimRin
1

votes
0

answer
68

Views

Angular 5 test fails “Module parse failed”

I am working on angular 5 application, and I am using pug as a template engine, the app working fine but when i tried to run testing, i got this error: ERROR in ./src/app/directives/footer/footer.component.pug Module parse failed: Unexpected token (6:20) You may need...
tarek noaman
1

votes
0

answer
124

Views

Chrome headless crashing due to blob and click event from karma test case

This is a duplicate question asked 2 years before but still i am taking this out from Pandora Box for no answer: How to mock Blob and Click() in jasmine Specs in angular js? Similar kind of a function exists here: function saveFile(data, fileName) { let url = URL.createObjectURL(new Blob([data])); l...
Mithun Shreevatsa
1

votes
1

answer
74

Views

foundation() is not a function error during Karma UT (Angular 5 + Foundation)

I recently upgraded my angular4 project to angular 5 project. When running the app, Foundation modal can open as intended. However, when running UT using Karma, the UT always complains about: Failed: $(...).foundation is not a function Tried the following things already: Included foundation in tscon...
blenzcoffee
1

votes
1

answer
1.1k

Views

How to access local variable of method in angular 2 unit test

I am trying write the unit test case for method in angular 2 with typescript. In that i have one local variable which is deciding which function will call. getData(){ let condition = route.queryParam.refer; if(condition === 'productWithChild'){ this.LoadProductWithChildData(); } else if(condition =...
Atul Sachan
1

votes
1

answer
358

Views

Angular testing: Failed to load html component

I caught this error when testing a component with templateUrl. I don't know how to fix it. After reading a post I added TestBed.resetTestEnvironment() and TestBed.initTestEnvironment() in the test file, but it doesn't solve the problem. It seems like something is missing in the config file and the...
laumonta
1

votes
0

answer
60

Views

Angular unit test cannot read property of subscribe

So im trying to create a unit test for this component and keep getting the error. TypeError: Cannot read property 'subscribe' of undefined. What is the reason for this and how would i properly implement a unit/integration test for this component? sidebar-item-component.html {{ item.label }} sidebar...
user3228452
1

votes
0

answer
913

Views

Configuring unit testing within an Ionic3 application

I'm implementing unit tests within an ionic3 project based on the following sample project: https://github.com/ionic-team/ionic-unit-testing-example. It works fine but I have some issues: I can see compilation errors (for jasmine) whereas these ones don't prevent from running tests karma start ./tes...
Thierry Templier
1

votes
0

answer
352

Views

How to add HttpErrorResponse object to GET mock call in Angular?

I am testing an interceptor in angular. Everything is OK apart adding the HttpErrorResponse object error.errorType parameter into my mocked request. Here is the code: it('should call showError method', () => { httpClient.get('url').subscribe( result => {}, (err) => { expect(timeoutService.showError)...
eugen sunic
1

votes
2

answer
266

Views

Angular 4 Output test not giving expected result

I have a component. It takes a value as its @Input. If the onDelete() method is called, there is an EventEmitter that will emit the value that was put in. I am trying to write a test for this component, and the value I get from the emitter is undefined, not the value I passed. Here is the test: im...
J Seabolt
1

votes
1

answer
139

Views

How to write unit and/or integration tests for an angular app that uses PouchDB

I am working with a large AngularJS + PouchDB codebase. We are using Protractor for end-to-end testing, but we found ourselves relying too much on end-to-end tests. These are slow and often fail intermittently. We would like to migrate as much of our testing to unit tests and/or integration tests. W...
jkndrkn
1

votes
1

answer
844

Views

Karma unit test / STORE - state undefined

Everything works OK when running the application but in the Account unit test it seems like none or my states have been initiated. Is there anything obvious I am doing wrong? Here is the error. Test error: The create selector in index.js is returning a function with undefined parameters but only dur...
Ashley Zattelman
1

votes
0

answer
25

Views

How to load a angularjs controller's templateUrl into a jasmine test?

I am new to angular and jasmine, so this is probably a simple one. However, I am having trouble accessing the HTML template from the jasmine test. I create the controller with a beforeEach. beforeEach(angular.mock.module('yeomanApp')); beforeEach(angular.mock.module('yeomanApp.services')); beforeE...
GC_
1

votes
0

answer
29

Views

Prevent accidental change of event name emitted by child component

How can I prevent accidental change of event name emitted by child component? @Component({ selector: 'app-update', template: '' }) export class ParentComponent { doReboot() { console.log('reboot action started'); } } @Component({ selector: 'app-reboot-panel', template: 'Reboot' }) export class Reboo...
koral
1

votes
0

answer
394

Views

Karma: Error: [$injector:nomod] Module 'app' is not available

I am new to Angular World and very beginner at Karma. I am receiving the following error when I am trying to run the Karma-Jasmine Unit test. { 'message': 'An error was thrown in afterAll\nUncaught Error: [$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgo...
Ankit Prajapati

View additional questions