karma-jasmine

Angular Testing, dynamically change ActivatedRoute params for different test cases

孤街醉人 提交于 2019-12-12 10:39:28
问题 Component: @Component({ selector: 'app-test', templateUrl: './test.component.html' }) export class TestComponent implements OnInit { useCase: string; constructor( private route: ActivatedRoute, ) {} ngOnInit() { this.route.queryParams.subscribe(p => { if (p) { this.useCase = p.u; } }); } } Test Spec describe('TestComponent', () => { let component: TestComponent; let fixture: ComponentFixture<TestComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ AppModule ],

How to test an Angular controller with a function that makes an AJAX call without mocking the AJAX call?

為{幸葍}努か 提交于 2019-12-12 09:52:35
问题 I have a function in a controller that calls a service which in turn calls another service, which makes the AJAX call and returns the promise. To put it simply: MainController call = function(){ //Handle the promise here, update some configs and stuff someService.call().then(success, failure); } SomeService return { call: function(){ return SomeOtherService.call(); } } SomeOtherService return { call: function(){ return $http.get(someUrl); } } How do I test the main controller's call function

angular is not defined error when karma test invoked

跟風遠走 提交于 2019-12-12 09:32:14
问题 I'm sure this has something to do with angular-mock.js but I cant figure what I need to do as everything seems to be fine. I'm just going by the default setup from angular-seed app. Please help get rid of the problem karma.conf.js module.exports = function(config){ config.set({ basePath : '../', files : [ 'bower_components/angular/angular.js', 'bower_components/angular-route/angular-route.js', 'bower_components/angular-mocks/angular-mocks.js', 'app/js/**/*.js', 'test/unit/**/*.js' ],

mock angular service/promise in a karma/jasmine test

家住魔仙堡 提交于 2019-12-12 07:08:33
问题 I'm trying to write a karma/jasmine test and I would like some explanations about how mocks are working on a service which is returning a promise. I explain my situation : I have a controller in which I do the following call : mapService.getMapByUuid(mapUUID, isEditor).then(function(datas){ fillMapDatas(datas); }); function fillMapDatas(datas){ if($scope.elements === undefined){ $scope.elements = []; } //Here while debugging my unit test, 'datas' contain the promise javascript object instead

Varaible declared is not defined in spec while testing

和自甴很熟 提交于 2019-12-12 05:52:02
问题 Here is my actual AzureService declare var WindowsAzure; declare var config; @Injectable() export class AzureService { azureUrl; client: any; programmes: Programme[]; selectedProgramme: Programme; orderSummary: Order; constructor() { this.client = new WindowsAzure.MobileServiceClient(this.azureUrl);} } Here is my dashboard spec describe('DashboardComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ DashbaordComponent, StatusComponent ], providers:[

Karma disconnects before all tests run

安稳与你 提交于 2019-12-12 05:22:44
问题 We are using karma as the test runner for jasmine unit tests, testing an Angular application. We have over 6000 tests. Karma is so slow to run tests, and never gets past about 2700 tests (11 mins). Is there a limit to the number of tests Karma can run, or is it normal for the performance of the test runner to degrade so much as the number of tests increase? // Karma Config file module.exports = function(config) { config.set({ basePath: '../', frameworks: ['jasmine'], files: [ ...list of files

Unit Test AngularJs Jasmine error: Expected spy login to have been called

随声附和 提交于 2019-12-12 05:09:37
问题 I'm new testing with AngularJs and Jasmine. I'm trying to test a login POST $http service. I'm not pretty sure how to do it, but what I have I'm getting an error and I dont know why. This is my login.service.js: (function () { 'use strict'; angular .module('app') .service('loginService', loginService); /** @ngInject */ function loginService($http) { var url = 'http://localhost:8080/login'; var service = { login: login }; return service; // ////////// // function login(user) { return $http

karma/angularjs how to test run block with an asynchronous service

為{幸葍}努か 提交于 2019-12-12 04:49:10
问题 How can I test like: init.js lama.system module angular.module('lama.system', []) .config(['$httpProvider', function($httpProvider) { // Crossdomain requests not allowed if you want do cors request see filter.php $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; }]) .run(['$rootScope', '$state', '$log', 'Global',function ($rootScope, $state, $log, Global) { $rootScope.$state = $state; $rootScope.$log = $log; $rootScope.global = Global; }]); controllers.js lama

An Angular2 app with karma & jasmine throws errors with multi-level directory structure

旧城冷巷雨未停 提交于 2019-12-12 04:36:29
问题 I am building an Angular 2 app with the current 4.0.0-beta.1 release. After many hours of struggle, I got karma running. I'm now trying to get a jasmine tautology test (true=true) to run, but karma reports: "Uncaught ReferenceError: describe is not defined" Here are the relevant code sections: karma.conf.js module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine'], // these plugins seem to be necessary. Without them, an error about a missing require in app

Angular2 testcase shows No provider for NgControl

£可爱£侵袭症+ 提交于 2019-12-12 04:24:29
问题 ng test shows the below error but it works as expected in reality. Error: Template parse errors: No provider for NgControl (" <div class="form-group"> <label class="control-label">Location</label> [ERROR ->]<select class="selectpicker" *ngIf="locations" data-style="btn btn-primary btn-round" title="Select A"): VehicleFormComponent@27:4 No provider for NgControl (" <div class="form-group label-floating"> <label class="control-label">Is Available</label> [ERROR ->]<md-slide-toggle [(ngModel)]=