Questions tagged [karma-jasmine]

0

votes
0

answer
2

Views

Karma test for DataTable options giving unexpected object property

I am testing options being passed into DataTables.net I am trying to test the order option but am getting this error when I run the test Expected object not to have properties _idx: 0; I have not set _idx anywhere in my DataTable instance. I do not know where it is coming from. This is my test: con...
gwar9
1

votes
0

answer
12

Views

Form submits without data in unit test

I have a form that uses components from Angular Material. I want to test that the form submits with the expected data. I will post a simplified version of my code below, but basically my test changes the value of an input and simulates a click on the submit button. I was able to confirm that the inp...
Brett
1

votes
2

answer
282

Views

Does Karma coexist with Jasmine?

From the online definition: Karma: is a tool which spawns a web server that executes source code against test code for each of the browsers connected. The results of each test against each browser are examined and displayed via the command line to the developer. Jasmine: is a development framework f...
masterach
1

votes
0

answer
9

Views

Angular[karma] Async testing on Observable

I try to test an async case. My component: ngOnInit(private service: MyService) { this.isLoading = true; this.service.getData().subscribe((data) => { this.data = data; this.isLoading = false; }); } As you can see i set loading to true and when the data have been checked isLoading become false. This...
Florian
0

votes
1

answer
5

Views

Gitlab CI running Angular Jasmine tests crashing without error

Having just setup Gitlab CI to run the Jasmine tests in my Angular project, I found the pipeline would bomb out with very little indication of the cause. All my tests would pass when run locally using ng test or locally in headless Chrome (having followed docs and another guide to set that up). Howe...
Greg Brown
0

votes
0

answer
4

Views

Video tag with controls attribute causing unit tests to fail

I am building a webapp with Angular 7.2.4. I am using the default unit testing library that the angular CLI (7.3.1) comes with. I keep running into this error as a failure when the unit tests run: An error was thrown in afterAll\nResizeObserver loop limit exceeded thrown It seems that the controls...
Devon Taylor
1

votes
1

answer
508

Views

How to stub imported module without methods in Angular?

I have an Angular Application with Jasmine Testing Framework. The Application has a Service called AuthService that handles decoding JSON Web Tokens: auth.service.ts import * as jwtDecode from 'jwt-decode'; ... @Injectable() export class AuthService { ... public getTokenPayload(token) { return jwtDe...
Nicky
1

votes
1

answer
3.6k

Views

NullInjectorError: No provider for HttpClient! Unit Testing a service

I have been trying to unit test a basic service today and I keep getting this error: Error: StaticInjectorError[HttpClient]: StaticInjectorError[HttpClient]: NullInjectorError: No provider for HttpClient! 'Error: StaticInjectorError'. I have been searching SO and Google for answers and all I fin...
Lotus_8
1

votes
1

answer
1.5k

Views

PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR ReferenceError: Can't find variable: angular

I have Node v4.1.1, npm v2.14.4, Karma version: 0.13.15and following this tutorial http://mcgivery.com/unit-testing-ionic-app/ to test my IONIC Application. I am getting this error when I am trying to run a test PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR ReferenceError: Can't find variable: angular at...
Ahmad Abbasi
1

votes
1

answer
1.3k

Views

Karma + Jasmine + JSONFixtures: Cannot read property 'ajax' of undefined

Background: I am trying to write unit tests for my javascript jsonTransformer, which transforms JSON-Schema to project specific JSON. As first test i want to have a blackbox test for this transformer, which receives the input-JSON and compares the transformed JSON to the correct JSON. I am using Kar...
Ahnde
1

votes
1

answer
758

Views

Jasmine controller and mock service not being injected into the unit tests

This is my test_sp.js file: describe('Controller: MainCtrl', function() { var ctrl, mockBaseService; beforeEach(function() { mockBaseService = { cerrorMessages: 'whatever', sp: '[{'spName': 'Test'}]', // Calls back if errors. add: jasmine.createSpyObj('BaseService.add', ['sp']), logout: jasmine.crea...
user2719875
1

votes
1

answer
723

Views

directive with inline tpl containing ng-include

I have a directive with inline template containing a ng-include directive element. When karma testing my directive and logging the result of compiled element . the tesult contains a ng comment saying the ng-include is undefined . What do I make wrong ? The directive works fine but the karma testing...
talx
1

votes
1

answer
84

Views

what and how to do unit test for angular factories

Angular factory is great!! While writing unit test, it is kind of confusing, should we write unit test or not. I have following factory: (function(myApp) { myApp.factory('MyFirstFactory', function(MySecondFactory){ function MyFirstFactory(config){ this.value1 = 'value1'; setDefault(this); } MyFirstF...
Nish
1

votes
1

answer
665

Views

Jasmine test complaining about 'undefined' is not an object

I have checked other questions similar to my problem. but this problem can apparently be different in every case. Angular Jasmine Test complains TypeError: 'undefined' is not an object (evaluating 'fields.forEach')at discoverDependentFields Here is my discoverDependentFields function discoverDepe...
Maryam
1

votes
1

answer
1.1k

Views

Angular2, TypeScript, PhantomJS - Can't find variable: Audio

PhantomJS doesn't support HTML5 Audio tags, which is making it difficult to test my Angular2 app. I've looked around for a solution, but unfortunately I haven't been able to figure out a way to mock the Audio object or somehow get around this. I have an Angular2 service that looks like this: import...
topherlicious
1

votes
2

answer
959

Views

How to spyOn a function created inside the Jasmine beforeEach block of code?

This is my code: describe('Factory: BaseService', function() { var fctry, mockBackend; beforeEach(function() { module('BaseApp'); cb = function() {}; inject(function(_BaseService_, _$httpBackend_) { mockBackend = _$httpBackend_; BaseService = _BaseService_; }); }); it('logout() should POST to /logou...
user2719875
1

votes
1

answer
679

Views

Jasmine + karma + angular test create controller

Where I make mistake? How can I get instance of controller in Jasmine + angular? How can I resolve controller? I have no idea what should I use to resolve that. 'use strict'; angular.module('myApp.contact', ['ui.router']) .controller('contactCtrl', ['$scope', function ($scope) { $scope.contact = { n...
Peter Pan
1

votes
3

answer
58

Views

Unit Testing a Controller with specific syntax

Whenever, I am testing a controller and have something like this in it. $scope.isSomething = function (Item) { return ItemCollection.someItem(Item.attachedItem); }; giving error on karma console: TypeError: undefined is not an object (evaluating 'Item.attachedItem') I am simply calling the function...
harsh
1

votes
3

answer
463

Views

How to do a unit test for Http Get without using http backend, I want to mock the backend instead, I'm using jasmine and Angular 1?

How to do a unit test for Http Get without using http backend, I want to mock the backend instead of doing a real call with http backend. I'm using Jasmine, Karma runner with Angular version 1? This is my current code that works but using Http Backend: describe('appService', function() { beforeEach(...
AngularM
1

votes
1

answer
671

Views

How to test change on scope executed in directive controller

I have directive myItem. I want to change one property that is passed from parent to directive, so I use controller in myItem where I divide value by 60. Everything works fine on the website. Directive define(['angular', 'core', 'ui-bootstrap', ], function(angular, coreModule, uiBootStrap) { 'use...
ThePavolC
1

votes
2

answer
2.3k

Views

How to test code inside $(window).on(“load”, function() {}); in Jasmine

I have a javascript below, which appends a DIV on page load and hides it after 3 sec. var testObj = { initialize: function() { var that = this; $(window).on('load', function() { (function ($) { //Append Div $('body').append('TEST'); })(jQuery); that.hideAppendedDiv(); }); }, hideAppendedDiv: funct...
n92
1

votes
1

answer
448

Views

Angular Module not available when using karma/jasmine

I'm trying to test a controller from my project and I'm getting a module not found error. I've looked at similar questions/answers but the solutions havent worked for me. My Angular code is as follows: angular.module('atMain') .controller('MainController', ['$scope', 'atDirApi', 'atServer', '$sce',...
user2109258
1

votes
1

answer
905

Views

Karma Jasmine Angular Error: [$injector:nomod]

Short version: When I run karma, angular is telling me it cannot inject my 'common' module. The actual error is: Error: [$injector:nomod] http://errors.angularjs.org/1.5.5/$injector/nomod?p0=common Here's the details: My Karma test.js 'use strict'; describe('Testing ModuleToTest',function(){ beforeE...
westandy
1

votes
1

answer
393

Views

How to compile template HTML, and get beyond .html()?

Question: I would like to access the form within my template, and test it against validation, submit, etc. I believe I have the Karma/Jasmine test setup correctly, but I do not know how to access the form. test-module.view.html: Directive: (function(){ 'use strict'; angular.module('TestModule').dir...
westandy
1

votes
2

answer
5.9k

Views

TypeError: undefined is not an object (evaluating 'scope.awesomeThings')

I got this error every time I run grunt test command. I setup a project using yo angular and try to run example code given in yeoman's scaffold. I don't what went wrong here, below are code which I tried to test. controller/main.js angular.module('brandPortalApp') .controller('MainCtrl', function ($...
Mithlesh Kumar
1

votes
1

answer
2.2k

Views

Testing HTTP with mockbackends

I'm working on building out tests for my services in Angular 2. Building out the mock backends is proving to be a real trial. I have been able to test the services with it making actual HTTP requests successfully but I would like to keep these segregated from the third part. I've combed through th...
Aarmora
1

votes
3

answer
715

Views

Unit test controller with service in it

I'm trying to unit test a controller with a service injected into it. No matter what I seem to try, I get an error. Any assistance to help me get this going would be much appreciated. I'm using Angular/Karma/Jasmine to get run my tests. There seem to be a lot of posts with similar stories but this f...
Dave Cooper
1

votes
1

answer
1.3k

Views

Unit Testing Knockout Binding Handlers with Jasmine

I have created a binding handler dependent on moment which is used for formatting the date. I wanted to unit test this binding handler using Jasmine. Below is my binding handler code: define(['knockout', 'moment'], function (ko, moment) { 'use strict'; ko.bindingHandlers.date = { update: function (...
Ankit Tanna
1

votes
1

answer
386

Views

How can I unit test assignment to window.location on an Angular JS projection?

I'm working on an AngularJS/Javascript Single Page Application(SAP) that sits behind a custom reverse-proxy, using Keycloak for Single-Sign-On(SSO). When the user clicks 'logout', after doing some other things, the application will execute window.location = reverseProxyHost + '/logout'; to ensure th...
Brian Kessler
1

votes
2

answer
252

Views

javascript unit testing variables and code not encapsulated inside functions

how to write unit test for variables in a angular js file. fooFactory.spec.js .. describe('test fooFactory', function(){ it('test if statement', function(){ expect(?).toBe(?); // how to write a test to pass values to testVar // testVar runs before I can assign value to it. // even if I have setters...
patz
1

votes
2

answer
60

Views

How to send mocked response data to called through $http call?

I have a controller that calls a service and sets some variables. I want to test that those variables get set to the response. My Controller: tankService.getCurrentStats().success(function (response) { $scope.stats.tankAvgHours = response.tankAvgHours; $scope.stats.stillAvgHours = response.stillAvgH...
enfrost
1

votes
1

answer
372

Views

Faker.js Generating random paths doesn't work

I am using faker.js https://www.npmjs.com/package/faker to generate random data. It works fine although when I try to create a path like this faker.system.directoryPath() + '/' + faker.system.filePath() I have always got undefined in both, so it seems that it exists but doesn't return anything. Did...
ackuser
1

votes
1

answer
549

Views

How to unit test module with provider dependencies?

I have an existing angular app. Now I want to start with some unit tests. I use jasmine and karma to test my services. My problem is that I am not able to test a service with the $stateProvider dependency. What I am using: - angularjs 1.5.8 - angular mocks 1.5.8 My code: angular.module('starter.sta...
user3481997
1

votes
1

answer
69

Views

Unit test an angular controller and service which uses a promise?

I cannot get the test result to pass I'm using a very basic implementation to understand testing deeper. I have a factory which returns a promise, accessed from my controller. I want to test that the call succeeds and assigns the response to the repos var. Following is the code: 'use strict'; angula...
SinSync
1

votes
1

answer
181

Views

Angular 2 RC6 test HTTP.get throws error the get() method doesn't exist

I am trying to write a unit test for a method that includes an http.get method and I'm having issues getting it to work. I know that setting the class to use for Http as MockBackend is wrong and is why I get the error: get() method does not exist however I don't know what I should use for the mock c...
efarley
1

votes
2

answer
90

Views

Store all the links in a webpage as json data using jasmine js

I'm looking to store all the links in a webpage as json data and then checking them for validity using jasmine js. But so far I haven't had any luck as I couldn't find a way to do it. describe('savejson', function() { var map = new Map(); it('save', function(myarg) { browser.ignoreSynchronization =...
wolfsbane
1

votes
2

answer
149

Views

Angular controller not injected in test

I have a simple login controller: 'use strict'; angular.module('login', ['ngRoute']) .config(['$routeProvider', function ($routeProvider) { }]) .controller('LoginCtrl', ['$scope', '$route', 'LoginService', function ($scope, $route, LoginService) { var self = this; this.showGuestLogin = true; this.sh...
Si-N
1

votes
1

answer
1.5k

Views

Angular 2 Final Release Router Navigate Unit Test Error

I am getting Failed: Uncaught (in promise): Error: Cannot find primary outlet to load 'UserList' error. This happens when unit testing my login component that redirects to admin/userlist using this._router.navigate(['admin/userlist']); in the component. login.html: Login {{errorMessage}} {{success...
xphong
1

votes
1

answer
702

Views

How to fake being offline in Jasmine?

I have a javascript function which is supposed to behave differently when offline than online as a safeguard. I would like to have a Jasmine unit test which tests the function in both offline and online modes - e.g., // offline describe('When there is no connection to the internet', function() { be...
carmenism
1

votes
2

answer
274

Views

Generating sourcemaps for app code using karma and webpack

I have an ES6 (Aurelia) app that I'm running unit tests for using karma with webpack and babel. I am able to generate source maps for the test files, but not for the application files. My karma.config contains something like this: module.exports = function (config) { config.set({ basePath: __dirna...
yammerade

View additional questions