jasmine

Unit Test Expect SpyOn Not Found

為{幸葍}努か 提交于 2020-01-02 13:30:14
问题 I have a directive (restrict A) that handles an event click, and calls a service based on a value. Directive: define(function () { 'use strict'; var myDirective = function ($rootScope, myFactory) { return { restrict: 'A', scope: { _myValue : '=value' }, link: function(scope, element, attrs) { element.bind('click', function() { if (scope._myValue === 'red') { myFactory.red(); } if (scope._myValue === 'green') { myFactory.green(); } if (scope._myValue === 'black') { myFactory.black(); } }); } }

How to reset knockout bindings in Jasmine test

送分小仙女□ 提交于 2020-01-02 10:37:19
问题 I'm trying to write test for knockout feature with jasmine as below and I'm getting following error: Error: You cannot apply bindings multiple times to the same element. describe("ThreeStepNavigationView", ()=> { var testSubject; var SmallNavigationStates = ['ribbon','expanded']; var ExtraSmallNavigationStates = ['collapsed','ribbon','expanded']; beforeEach(()=> { loadFixtures('SidebarAndSiteHeader.html'); testSubject = new Mobile.Navigation.ThreeStepNavigation.View(); ko.applyBindings

Unit testing Angular directive with $http

自闭症网瘾萝莉.ら 提交于 2020-01-02 10:24:36
问题 I have an Angular directive that, when attached to an <input> , waits one second after user input before querying an endpoint with $http. In short, it's meant to check username uniqueness. It looks like this: .directive('sgValidUsername', ['$http', function(http) { var waitTimer; var checkIfUserExists = function(e, ctrl) { http.get('/publicapi/users/' + e.target.value + '/exists') .success(function(data) { ctrl.$setValidity('unique', !data.exists); }); }; return { restrict: 'A', require:

Unit testing Angular directive with $http

两盒软妹~` 提交于 2020-01-02 10:24:13
问题 I have an Angular directive that, when attached to an <input> , waits one second after user input before querying an endpoint with $http. In short, it's meant to check username uniqueness. It looks like this: .directive('sgValidUsername', ['$http', function(http) { var waitTimer; var checkIfUserExists = function(e, ctrl) { http.get('/publicapi/users/' + e.target.value + '/exists') .success(function(data) { ctrl.$setValidity('unique', !data.exists); }); }; return { restrict: 'A', require:

Testing a service function POST response with Jasmine

感情迁移 提交于 2020-01-02 08:08:07
问题 I'm not entirely sure how to do this but I have a endpoint URL which is a POST request for login authentication. When you add a request payload, you will get either a successful login credential or an error. However, I seem to have problems with fetching the response. Here is my spec file: describe('Service: AuthFactory',function(){ beforeEach(function () { module('ui.router'); module('users'); module('main'); }); var AuthFactory, httpBackend; beforeEach(inject(function($httpBackend,

Angular 1.5 && Async/Await && jasmine tests

心已入冬 提交于 2020-01-02 07:58:52
问题 I already looked everywhere but could not find a solution yet for my particular case. We are using angular 1.5 and a Karma/Jasmine setup for unit tests. In the initial source code, I used ES2017 async/await in the controller. That seemed to work fine as long as I added $apply of $digest manually at the end. So for example: async function loadData() { try { vm.isLoading = true; vm.data = await DataService.getData(); $scope.$apply(); } catch (ex) { vm.isLoading = false; } } To write an

$browser.$$checkUrlChange is undefined in a jasmine test

浪子不回头ぞ 提交于 2020-01-02 03:41:04
问题 I have the following test: it('should maintain a bind between the data at the $scope to the data at the ingredientsService', function(){ $scope.addFilters('val1', $scope.customFiltersData, 'filter1'); $scope.$digest(); expect($scope.customFiltersData).toEqual(ingredientsService.filters()); }); I get the following error: TypeError: undefined is not a function at Scope.$digest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12502:17) at null.<anonymous> (/home/oleg/dev/vita

Jasmin + karma: “Error: Unexpected value 'HttpClient' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.”

假装没事ソ 提交于 2020-01-02 03:20:09
问题 I'm using jasmine as a test framework and karma as a test runner. I'm trying to create an HttpClient object so I could create a service that as a depedency to this object: TestBed.configureTestingModule({ declarations: [HttpClient], imports: [HttpClient], providers: [HttpClient] }); TestBed.get(HttpClient); But I'm getting the following error: Error: Unexpected value 'HttpClient' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation. Any one have an idea how to solve

Is 'repeater' in this angular tutorial a jasmine concept?

。_饼干妹妹 提交于 2020-01-02 03:01:26
问题 Looking through angular js tutorial, I do not understand where the repeater (function?) comes from in a jasmine test. Is this a jasmine or an angular construct? The page does have an ng-repeat attribute in a <li> element - but I dont see how that translates to the reference to 'repeater' in the test it('should be possible to control phone order via the drop down select box', function() { //let's narrow the dataset to make the test assertions shorter input('query').enter('tablet'); //where

Angular mock fails to inject my module dependencies

五迷三道 提交于 2020-01-02 01:07:18
问题 I want to test an Angular controller for my application fooApp , defined as follow: var fooApp = angular.module('fooApp', [ 'ngRoute', 'ngAnimate', 'hmTouchEvents' ]); ... The controller, MainCtrl is defined: "use strict"; fooApp.controller('MainCtrl', function ($scope, $rootScope, fooService) { ... } So I've tested several ways to create a test, like this one: 'use strict'; describe('MainController test', function () { var scope; var controller; beforeEach(function () { angular.mock.module(