karma-jasmine

currentSpec in Jasmine 2 is undefined

纵饮孤独 提交于 2019-12-13 02:34:56
问题 I want to upgrade my test suite to the latest Jasmine version 2.3.4. I have some custom helper methods for testing AngularJS stuff inside my spy_helper.js like this: (function() { this.stubPromise = function(service, functionName) { var $q = jasmine.getEnv().currentSpec.$injector.get("$q") var $rootScope = jasmine.getEnv().currentSpec.$injector.get("$rootScope") var deferred = $q.defer(); var spy = spyOn(service, functionName).andReturn(deferred.promise); spy.andResolveWith = function(value)

Can't Find JQuery When Running 'ng test' Command

主宰稳场 提交于 2019-12-12 22:39:23
问题 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 added JQuery in the following

How to inject ngRoute into Jasmine / Karma AngularJS unit test?

谁都会走 提交于 2019-12-12 20:28:15
问题 I'm trying to get a basic unit test example working. It all works fine with this app.js var whapp = angular.module('whapp', []) .filter('reverse',[function(){ return function(string){ return string.split('').reverse().join(''); } }]); and this spec.js describe('Filters', function(){ //describe your object type beforeEach(module('whapp')); //load module describe('reverse',function(){ //describe your app name var reverse, rootScope; beforeEach(inject(function($filter){ //initialize your filter

Howto point to typescript file instead of javascript file karma runner webstorm

梦想的初衷 提交于 2019-12-12 18:33:20
问题 I have my project setup in WebStorm to transpile TypeScript into JavaScript etc. So I write my code as well as my tests in TypeScript. When I run "Karma with coverage" in webstorm it all runs fine. But, when for example a tests fails, the output keeps pointing to the javascript files. So when I click the failing test, it opens up the javascript file instead of the typescript file Is there a way to integrate the mappings here as well? My current preprocessor setup: preprocessors: { 'app

How to test Location in angular 2 with karma+jasmine

折月煮酒 提交于 2019-12-12 17:16:34
问题 Angular 2 v.2.0.0 - TS + karma + jasmine. I test this function - back on click to previously page: public isClick: boolean = false; public backClicked(location: Location): void { if (!this.isClick) { this.isClick = true; this.location.back(); } } And this is my test: describe("NavBarComponent", () => { describe("function backClicked(): void", () => { let testNavBarComponent: NavBarComponent; let loc: Location; beforeEach(() => { testNavBarComponent = new NavBarComponent(null); }); loc =

AngularJS: inject causing error in tests

丶灬走出姿态 提交于 2019-12-12 16:42:54
问题 I am unable to use inject in my tests. Both angular and angular-mocks are version 1.3.14 I am completely lost here. Any ideas will be greatly appreciated! This causes an error: describe("factory: Account", function () { var $httpBackend; var $rootScope; var Account; beforeEach(module('app')); beforeEach(inject(function() { // $httpBackend = _$httpBackend_; })); it("Should fetch account", function() { }); }); But if I remove inject it will pass: describe("factory: Account", function () { var

Angular2 Karma test says “TypeError: this._subscribe is not a function”

♀尐吖头ヾ 提交于 2019-12-12 14:40:20
问题 I have an Angular 2 application that works OK so far. My GlobalsService.getGlobals() fetches "USA States" through my OptionService.getOptions(). Where my code falls down is in Karma / Jasmine testing. When I call getGlobals() in my current test setup I get the "this._subscribe is not a function" error. I'm finding it hard to debug this because Google Chrome isn't cooperating. My getGlobals() code with debugging added. I split the code between getOptions() and .subscribe() to see what is going

No message in 10000 ms. Jasmine Karma RequireJSS

霸气de小男生 提交于 2019-12-12 13:33:41
问题 I started without knowing much in AngularJS. When I run : .\node_modules\.bin\karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=PhantomJS I get the following message : WARN [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Disconnected (1 times), because no message in 10000 ms. I started with the angular-seed project, from there I made adjustment for my needs. I want to use jasmine as my testing framework. So I made my test case based on the current angular-seed one:

How to mock $scope.variables in jasmine

本秂侑毒 提交于 2019-12-12 13:01:07
问题 I have the following test case CompanyCtrlSpec.js describe('ViewCompanyCtrl', function () { var $rootScope, scope, $controller , $q ; beforeEach(angular.mock.module('MyApp')); beforeEach(inject(function ($rootScope, $controller ) { scope = $rootScope.$new(); createController = function() { return $controller('ViewCompanyCtrl', { $scope: scope, company : {} }); }; })); it('the company type should be equal to an object', function () { var controller = new createController(); //some assertion })

Mocking ngResource in Angular unit tests

扶醉桌前 提交于 2019-12-12 10:56:33
问题 I have an ngResourceMockFactory which looks like this: (function() { 'use strict'; angular.module('app') .factory('NgResourceMock', ngResourceMockFactory) ; ngResourceMockFactory.$inject = []; function ngResourceMockFactory() { function NgResourceMock() { var context = this; context.$promise.then = function() { context.prototype.$promise.then.apply(context, arguments); }; context.$promise.finally = function() { context.prototype.$promise.finally.apply(context, arguments); }; } NgResourceMock