karma-jasmine

Jasmine test case error 'Spy to have been called'

二次信任 提交于 2019-12-11 03:47:33
问题 I'm writing jasmine test case for below angular function and getting test case failed message "Expected spy [object Object] to have been called". $scope.displayTagModelPopup = function() { var dialogOptions = { templateUrl: 'views/mytags.html', controller: 'TagsCtrl', size: 'lg', resolve: { tagsAvailable: function() { return $scope.availableTags; } } }; ModalDialogFactory.showDialog(dialogOptions).then(function(result) { $scope.selectedFields = []; $scope.selectedFieldIds = []; angular

Test Angular resolve method

本小妞迷上赌 提交于 2019-12-11 03:23:55
问题 I have Angular with ui-router, so toResolve variable will be resolved in my SomeController .state('some.state', { url: '/some', controller: 'SomeController', templateUrl: '/static/views/some-state.html', resolve: { toResolve: function(Resource) { return Resource.get(function(response) { return response; }); }, But how to test this functionality with Jasmine? Let's suppose that I forget return statement, therefore the toResolve in my scope will be undefined . 回答1: Use services to make

Can't resolve all parameters for ApplicationModule: (?)

不羁的心 提交于 2019-12-11 02:40:07
问题 I just migrated an application module to be an importable library. I'm trying to make the tests work correctly, just as they worked before, but I get this error: Error: Can't resolve all parameters for ApplicationModule: (?). at syntaxError (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:1275:17) at CompileMetadataResolver._getDependenciesMetadata (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler

Angular Jasmine tests fail with minified source

自古美人都是妖i 提交于 2019-12-11 02:26:10
问题 I'll try to approach this question with a little bit of abstraction, since going into the code details would be useless. I have an angular module that is split in 2 source files, say source1.js and source2.js . Then i have 3 unit test files which are designed to test 3 angular service/factory/provider. The project layout is as follows: root | -dist | -source.min.js -src | -source1.js -source2.js -tests | -unit | -service1.js -service2.js -service3.js All the tests, run with karma and jasmine,

Karma cannot load imported files

随声附和 提交于 2019-12-11 01:38:48
问题 I've been struggling for days now with the fact I cannot run any real test with Karma. I can run tests which do not require imports (like basic sanity tests) but as soon I have to import something from my app I get the error: system.src.js:1085 GET http://localhost:9876/base/dist/components/test.service 404 (Not Found)fetchTextFromURL @ system.src.js:1085(anonymous function) @ system.src.js:1646ZoneAwarePromise @ angular2-polyfills.js:589(anonymous function) @ system.src.js:1645(anonymous

Angula2 Karma Can not load “webpack”!

笑着哭i 提交于 2019-12-11 01:33:56
问题 I have been working on an Angular2 project (Webpack + Karma) for a couple of months now which bases on a slightly older version of this starter: https://github.com/preboot/angular2-webpack Everything had been working fine until I checked my project out on a different computer. After installing the dependencies using npm install I tried to run my tests. This is where this error msg appeared which I can not explain .... Can not load "webpack"! WebpackOptionsValidationError: Invalid

TypeError: _this.handler.handle is not a function error

瘦欲@ 提交于 2019-12-11 01:01:17
问题 I am getting this error that this.handler.handle is not a function in my unit testing in Angular 6 using karma/jasmine. This error comes up in my command line when I type the 'ng test' command in my project folder. Chrome 67.0.3396 (Windows 10.0.0) AppComponent should create FAILED Failed: _this.handler.handle is not a function TypeError: _this.handler.handle is not a function for a test that should create AppComponent here is my .spec file import { async, ComponentFixture, TestBed } from '

how to test $http call in angular js?

一个人想着一个人 提交于 2019-12-11 00:53:57
问题 I am trying to test my $http request using karma and jasmine.I make one controller and inject a service .In service I call $http service.I need to test that service how I will test this service this is my controller. angular.module('app',[]).controller('first',function($scope,data){ $scope.name='test'; data.getData().then(function(data){ console.log(data); }) }).factory('data',function($http){ return{ getData:getData } function getData(){ return $http.get('data.json').success(successCall)

Karma unit test / STORE - state undefined

别说谁变了你拦得住时间么 提交于 2019-12-11 00:24:20
问题 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 during karma tests. Account.component.ts import { Component, OnInit, OnDestroy, ChangeDetectionStrategy } from '@angular/core'; import * as fromAuth from '../../../auth/store/reducers'; import { Store

Angular 2 - Error: No provider for Token FirebaseAppName

£可爱£侵袭症+ 提交于 2019-12-11 00:14:47
问题 My app is running fine, but I cannot get my tests to pass with Firebase. Error: No provider for Token FirebaseAppName! Here is me spec: import { TestBed, inject } from '@angular/core/testing'; import { ApiService } from './api.service'; import { HttpModule } from '@angular/http'; import {FIREBASE_PROVIDERS, defaultFirebase, AngularFire} from 'angularfire2'; describe('ApiService', () => { beforeEach(() => { const firebaseConfig = { apiKey: "foo", authDomain: "bar", databaseURL: "baz",