jasmine

Jasmine - Two spies for the same method

醉酒当歌 提交于 2019-12-11 21:22:56
问题 I'm new to Jasmine and I wanted to know if we can create 2 spies for the same method. Here is what I'm trying. describe('something', function () { beforeEach(function () { mySpy = jasmine.createSpyObj('mySpy', 'functionInInterest'); mySpy.functionInInterest.andCallFake(function (cb) {cb(something);}); } //Some Test Cases describe('Here is the action!', function () { mySpy = jasmine.createSpyObj('mySpy', 'functionInInterest'); mySpy.functionInInterest.andCallFake(function (cb) {cb

$scope exists on browser debugger, but does not exist in terminal

柔情痞子 提交于 2019-12-11 20:21:58
问题 I have a directive that is depended on a controller which gets data from an api though Ajax call. It works correctly. I am trying to test it using jasmine and the strange issue is that when I debug the code and check for a value of let's say $scope.measurement it returns true, but when I run in the terminal it can't find $scope.measurement and raises an error Expected undefined to be true . no clue what can be the issue. I thought the problem might be with an isolated scope, but the element

AngularJS: test $scope methods that make async calls

Deadly 提交于 2019-12-11 19:53:20
问题 I'm trying to test a controller method I have on the $scope. That method makes an async call and get a promise back. When the promise is resolved, the result is assign to a variable on the $scope. The test I'm trying to come up with is simple: assign null to the $scope variable, call the method, wait for the call to finish, expect the result to be assign to the $scope variable. For some reason, the promise never resolves. See http://plnkr.co/edit/qxs5Y54NvhA24Fk4MPv2?p=preview Here is the

Angular Jasmine - Test case gets failed in http HEAD request while on Flush

落花浮王杯 提交于 2019-12-11 19:45:28
问题 I'm trying to write a test case for the HTTP HEAD Request, it works fine without flush method. If I triggered the flush method the chrome browser gets disconnect. I don't know what needs to pass as a param to the flush method. Example: Service Method processData(id): void { const url = `http://localhost:5000/data/${id}`; this.http.head(url).subscribe(() => { console.log('Success'); // Rest of the code - TODO }, (error) => { console.log('Failed'); // Rest of the code - TODO }); } Test Case

Mocking resolve in state using Jasmine & Angular

杀马特。学长 韩版系。学妹 提交于 2019-12-11 19:39:42
问题 I'm trying to mock the resolve functions inside the $state of my ui-router file, but I can't seem to get it to work. Here's my router code: $stateProvider .state('state.of.page', { url: '/url-to-page', template: require('./page-template.html'), controller: 'PageCtrl', controllerAs: 'page', resolve: { /** * Cloning of page object in case user leaves page * without saving */ pageObjClone: ['pageObj', function (pageObj) { return angular.copy(pageObj); }], pageTemplate: ['template', function

Angular Jasmine FormControl Unit Test valueChanges

冷暖自知 提交于 2019-12-11 19:36:16
问题 I want to unit test my following method: this.boxValue = ''; subscribeToFilterChanges(): void { this.filterBox.valueChanges .subscribe( data => { if (data) { this.boxValue = data.trim().toLowerCase(); } } ); } filterBox is a FormControl: filterBox = new FormControl(''); HTML is: <mat-form-field appearance="standard"> <input matInput [formControl]="filterBox" id="filterBox-input"> </mat-form-field> I've written the unit test as: it('verify filter changes', () => { let filterBoxInput = fixture

How to write tests for classes with inheritance

这一生的挚爱 提交于 2019-12-11 19:27:37
问题 I have a project written in Angular 1.3 that have services that inherit each other. There is a BaseApiService , which is a parent class and it implements a lot of functionality related to API calls. It looks like that: .factory('BaseApiService', function ($resource, apiHost, apiUrl, WebSocketService, $q, $timeout) { //initializer return function (resourceName, options) { options = angular.extend({}, { resourceUrl: resourceName + '/:id', resourceParams: {id: '@id'}, resourceMethods: { 'get':

AngularJS : Testing directive, HTML not re-rendered after promise completion

强颜欢笑 提交于 2019-12-11 19:07:14
问题 I am writing some basic unit tests for my AngularJS app. I have some bindings on the UI with a scope variable inside my directive whichis populated on the completion of a promise. HTML: <div id="parent"> <div id="child" ng-repeat="l in aud"> // Other Stuff </div> </div> Directive: link: function(scope){ service.getArray().$promise.then(function(data){ scope.aud = data; } Test: describe('my module', function () { var $compile: ICompileService, $rootScope: IScope, directive: JQuery<HTMLElement>

Jasmine - trigger event not working

橙三吉。 提交于 2019-12-11 18:55:02
问题 Code that I'm trying to test: $(".toggle_item").on("change", function() { console.log("change triggered") item_name = $(this).data("name"); value = $(this).prop("checked"); if (Item.isValid(item_name) && cartModule.isUnique(item_name)) { cartModule.toggleItem(item_name, value); } }) Jasmine spec: describe("changing toggle item", function() { beforeEach(function() { console.log("in spec") affix(".toggle_item[data-name='ladder']") spyOn(cartModule, "isUnique") spyOn(Item, "isValid") $(".toggle

Protractor - How to generate execution report or display the console.log messages in an output text file

放肆的年华 提交于 2019-12-11 18:39:19
问题 I am using Protractor to test the Mobile hybrid app. I am using windows env. with javascript. I want to display the console.log messages in a separate text file after execution. or is there any way to generate the execution logs? I tried resultJsonOutputFile and http://eitanp461.blogspot.in/ or console.push message, but did not get the expected output. 回答1: If you just want all protractor outputs, simply redirect the output: protractor --option1=x --options2=y conf.js > /path/you/want/to/save