Search Posts

Category: karma-jasmine

Karma-Jasmine Test Case – Controller Undefined

In karma-Jasmine test case i get the error like undefined controller. My Controller Code: angular.module(‘MyApp’).controller(‘corporateController’, function ($rootScope, $scope, $http, $timeout, $location,$q) { $scope.pwd = “”; $scope.testCheck = function () { if ($scope.pwd.length > 8) { $scope.strgth = “strong”; } if ($scope.pwd.length < 8) { $scope.strgth = “Weak”; } } }); My Test Case Code: describe(‘Controller Test Spec’, function () { beforeEach(module(‘MyApp’)); it(‘scopeTestSpec’, inject(function ($controller, $rootScope) { var scope = $rootScope.$new(); console.log(scope); //console.log($controller); var ctrl = […]

Unit testing that a component is rendered in an angular app

I have an Angualr 1.5 app that looks like this. The app has a mix of Typescript and Javascript components: import * as angular from ‘angular’; import {B} from ‘./b.component’; import {A} from ‘./a.module’; export const c= ‘c’; angular.module(c, [a]) .component(B.componentId, new B()); The corresponding HTML looks like this <div> <div id=”holder”> <a></a> </div> </div> And here is the b.module angular.module(a, []) .component(b.componentId, new A()); And here is the a.component import * as ng from […]

Mocking Angular service in Jasmine throws method not found

In this plunk I have an Angular/Jasmine test that attempts to mock a service function. The service function mocked needs to be invoked by another function in the service. This is the error I get: Error: getTheDate() method does not exist And this is my attempt, where the function tested getTheMonth should invoke a mocked function getTheDate, it seems that spyOn is used incorrectly: angular.module(“mymodule”, []) .service(‘myService’, function(){ this.getTheDate = function() { return new Date(); […]

Why won’t "ng test" find my unit tests within npm packages?

I recently upgraded my team’s enterprise application to @angular/cli 1.4.5, and since then have not been able to run unit tests on the code within our private npm packages. Prior to the upgrade I had no problems running my unit tests, but ng test now only picks up unit tests located within src/app. Included are the src/test.ts file and karma.conf.js file, as well as the console output when trying to run the contexts from the […]

Jasmine / Karma test error using angular.mock.inject

I am trying to run some Angular karma/jasmine tests to test functionality for ui-grid. But my issue is that my tests are breaking when they get to the injector.Here is my error: C:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:280261 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:11940 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:277471 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:139593 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:1071148 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:1069633 C:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:1007389 TypeError: undefined is not a constructor (evaluating ‘$compile(‘<bss></bss>’)’) in C:/Users/schmitzb/Projects/RCO/rco-project/test/index.js (line 9) C:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:1008235 I’m doing something incorrectly at this line I believe, when I remove this line and put in a different module it doesn’t error: […]

Can’t Find JQuery When Running ‘ng test’ Command

I have created a project using new angular-cli version and I made the project up and running. When I run ng serve and ng build command it works perfectly without giving any errors. But when I tried to run ng test it shows me errors like this. theme.provider.ts (53,31): Property ‘removeClass’ does not exist on type ‘JQuery’. theme.provider.ts (64,35): Property ‘addClass’ does not exist on type ‘JQuery’. theme.provider.spec.ts (7,30): Cannot find name ‘$’. I have […]

Unable to run angular4 test cases

I am getting an error (p.s. attached screenshot) when I run ng test in my angular4 app. I have not changed anything as such this just added some test specs in app.component.spec.ts My karma.config.js file has following code module.exports = function (config) { config.set({ basePath: ”, frameworks: [‘jasmine’, ‘angular-cli’], plugins: [ require(‘karma-jasmine’), require(‘karma-chrome-launcher’), require(‘karma-remap-istanbul’), require(‘angular-cli/plugins/karma’) ], files: [ { pattern: ‘./src/test.ts’, watched: false } ], preprocessors: { ‘./src/test.ts’: [‘angular-cli’] }, mime: { ‘text/x-typescript’: [‘ts’,’tsx’] }, […]

Test an asynchronous function not within a service

If I have a directive that takes a function from the scope, and that function is asynchronous how could I test that? For example angular.module(‘myApp’).factory(‘AsyncService’,() => { return { async: // function that returns a promise } }) angular.module(‘myApp’).directive(‘asyncDirective’, () => ({ scope: { async: = }, link: scope => { scope.async.then(//do something) } })); angular.module(‘myApp’).controller(‘ctrl’, ($scope, AsyncService) => { $scope.asyncService = AysncService; }); <async-directive async=”asyncService.async” /> The above code is an example of how […]

angular.module(…).info is not a function in angular unit testing

I am doing unit testing using karma-jasmine of angular app. i am using laravel for backend.while running kara test runner getting ” Uncaught TypeError: angular.module(…).info is not a function at angular-mocks.js:806“. i don’t what going wrong, i am attaching screenshot of files. Error Screen: karma.conf.js: Test Case Js Sceenshot: Angular Controller: Source: AngularJS

Next Page »