karma-jasmine

Angular2 - HTTP call unit testing

霸气de小男生 提交于 2019-12-08 11:58:17
问题 I am a beginner of angular2. My service.ts will be, import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import {Headers, RequestOptions, URLSearchParams} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; @Injectable() export class HomeService { url : string; constructor(private _http: Http) {} getUserInfo(userId : string) { this.url =

Ionic 2 : Test with jasmine and karma error 'ng test'

时光总嘲笑我的痴心妄想 提交于 2019-12-08 06:33:36
问题 I try to follow this tutorial : http://lathonez.com/2017/ionic-2-unit-testing/ And when I run "ng test" I have this error : C:\xampp\htdocs\AppFineMobile>ng test 27 03 2017 11:55:00.556:ERROR [preprocess]: Can not load "angular-cli", it is not registered! Perhaps you are missing some plugin? No provider for "framework:angular-cli"! (Resolving: framework:angular-cli) Error: No provider for "framework:angular-cli"! (Resolving: framework:angular-cli) at error (C:\xampp\htdocs\AppFineMobile\node

AngularJS + Jasmine mock unit test $http factory of POST method

感情迁移 提交于 2019-12-08 05:14:02
问题 How I can make unit-test of $http factory, if it using post method, for example: // controller $scope.logOut = function (){ logOutFactory.logOut().then(function(resp){ }); }; // service app.factory('logOutFactory', ['$http', '$q', 'CONST', function ($http, $q, CONST){ var logoutApiUrl = CONST.URL+'logout'; return { logOut: function() { var deferred = $q.defer(); $http({ method: "post", url: logoutApiUrl }) .success(function (data) { deferred.resolve(data); }) .error(function (data) { deferred

Jasmine Test for ng-mouseenter

女生的网名这么多〃 提交于 2019-12-08 04:45:10
问题 I'm having trouble testing my directive with an ng-mouseenter directive. I'd like to test several things, but first off, I need to test that the method supplied to ng-mouseenter is called. my test: describe('hover tests', function () { it('the triggerPopover method should be called on hover', function() { spyOn($scope, 'triggerPopover'); var ars = jQuery(view.find('article.the-class-im-looking-for')); jQuery(ars[0]).trigger('mouseenter'); expect($scope.triggerPopover).toHaveBeenCalled(); });

Call a controller function from Karma and Jasmine testing

断了今生、忘了曾经 提交于 2019-12-08 04:00:13
问题 This is my angular controller :- angular.module('authoring-controllers', []). controller('NavCtrl', function($scope, $location, BasketNavigationService) { $scope.test= function() { $scope.testVar = BasketNavigationService.showBasketList(); }; }); TEST class describe('NavCtrl', function() { var scope, $location, createController; beforeEach(inject(function ($rootScope, $controller, _$location_) { $location = _$location_; scope = $rootScope.$new(); createController = function() { return

Angular Unit test fails when i try to inject a service

大城市里の小女人 提交于 2019-12-08 02:01:45
问题 I have a angular where i want to test my controllers and services with karma and jasmine. I wrote some tests and they worked. Then i did some big changes to my angular project. Now my tests are all failing and i can't figure out why. I commented everything out in my tests and just wanted to check if the $controller service gets loaded. But not even this works. My module definition: angular.module('cManagement', [ 'angular-multi-select', 'ngCookies', 'ui.router', 'ui.bootstrap', 'pascalprecht

How can I resolve Angular unit test error: “An error was thrown in afterAll\n[object ErrorEvent] thrown”

被刻印的时光 ゝ 提交于 2019-12-08 00:42:42
问题 When I run ng test command in my angular project has error, it gives an error like that 10% building modules 1/1 modules 0 active04 12 2018 11:29:43.408:WARN [karma]: No captured browser, open http://localhost:9876/ 04 12 2018 11:29:43.414:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/ 04 12 2018 11:29:43.414:INFO [launcher]: Launching browser Chrome with unlimited concurrency 04 12 2018 11:29:43.418:INFO [launcher]: Starting browser Chrome 04 12 2018 11:29:53.540:WARN

How to fake being offline in Jasmine?

守給你的承諾、 提交于 2019-12-07 21:47:09
问题 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() { beforeEach(function(){ spyOn(navigator, 'onLine').and.returnValue(false); }); it('offline behavior happens', function() { myFunction(); expect(something).not.toHaveBeenCalled(); }); }); // online

Jasmine unit testing observable subscribe does not trigger

喜夏-厌秋 提交于 2019-12-07 15:06:50
问题 I'm using Angular 5 with Jasmine and Karma. I'm trying to test whether a certain function works but my subscribe doesn't trigger during unit testing. this causes my unit test to fail as I'm using the done function of jasmine. I want to make this unit test succeed. I've set the timeout interval to 20 seconds to see if it just took a while (which it shouldn't). I've tried to use async and fakeasync as well, but it doesn't trigger. Is it possible for me to make the subscription to trigger? this

Angular2 unit testing - why nativeElement has empty CSSStyleDeclaration

泪湿孤枕 提交于 2019-12-07 13:48:28
问题 I'm trying to test a simple header component that has a button and when being focused - opens a dropdown using just css visibility property. This is the html: <nav class="navigation"> <button type="button"> <span>click here</span> </button> <ul> <li> Text </li> <li> Text </li> <li> Text </li> </ul> </nav> This is the scss style: button { span { margin-right: 10px; } &:focus { + ul { visibility: visible; } } } ul { position: absolute; list-style: none; z-index: 1000; visibility: hidden;