jasmine

Karma-Jasmine: How to properly spy on a Modal?

泪湿孤枕 提交于 2019-12-01 06:09:37
问题 THE SITUATION: I am unit testing my Angular / Ionic app. I am having troubles with the modal. At the moment i can test that the modal has been called. That's all so far. I cannot test the proper show() and hide() method of the modal. I am getting the following errors: TypeError: $scope.modal_login.show is not a function Error: show() method does not exist TypeError: $scope.modal_login.hide is not a function Error: hide() method does not exist I think it depends entirely on the spy. I don't

Observable.fromPromise empty during unit testing

余生长醉 提交于 2019-12-01 06:05:02
问题 loadAdList$ is an Observable that taps into the actions$ stream: loadAdList$: Observable<Action> = this.actions$ .ofType<adActions.Load>(adActions.LOAD) .switchMap((action) => { return Observable.fromPromise(store.findAll('ad', action.payload) .then((ads) => { return new adActions.LoadSuccess(ads); }) .catch((err) => { return new adActions.LoadFail(err); })); }); It works in the browser, there is no problem with it. However, I want to unit test it as well: actions$ = hot('-a', { a: loadAction

What line is causing this Protractor error?

我的梦境 提交于 2019-12-01 05:51:28
Is there a way for Protractor to show in the console log what line the error occurred on? I just get this type of message: Message: Failed: Cannot call method 'click' of undefined Stack: Error: Failed: Cannot call method 'click' of undefined at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:104:16 at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15 at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20) at

Download file on Firefox with protractor

╄→гoц情女王★ 提交于 2019-12-01 05:51:05
I need to download a zip file on Firefox with protractor. On clicking on download link, Windows dialog asking to Open/Save the file pops up. So How can I handle that. What args do I need to pass to driver? With chrome I can do that with download: { 'prompt_for_download': false }, but what should i do with firefox. The problem is - you cannot manipulate that "Save As..." dialog via protractor/selenium . You should avoid it being opened in the first place and let firefox automatically download the files of a specified mime-type(s) - in your case application/zip . In other words, you need to fire

Getting error while using Jasmine with AngularJS

走远了吗. 提交于 2019-12-01 05:48:57
问题 I am using jasmin to test my AngularJs project with following code controllersSpec.js describe('myApp', function(){ beforeEach(angular.mock.module('myApp')); it('should have a mailctrl', function() { expect(myApp.mailctrl).toBeDefined(); }); }); controller.js var myApp = angular.module('myApp', []); myApp.controller('mailctrl', ['$scope', '$routeParams', '$rootScope', 'getMailData', '$angularCacheFactory', function ($scope, $routeParams, $rootScope, getMailData, $angularCacheFactory) { ##...

Jasmine and Requirejs in Resharper 7

我们两清 提交于 2019-12-01 05:46:04
问题 I'm trying to run some JavaScript code using jasmine and Resharper 7 within visual studio 2012. I follow the AMD pattern with the aid of requirejs. However, i haven't managed to make my test run in the Resharper test runner. Has anyone managed to do anything similar to that? 回答1: Use a named requireJS Module define("my/sut", function () { var MySut = function () { return { answer: 42 }; }; return MySut; }); And initialize the SUT with the asyncronus support of Jasmine. Don't forgot the

How to Test Value Returned in Promise from AngularJS Controller with Jasmine?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 05:40:31
问题 I have a controller that expose a function that returns some text after a rest call. It works fine, but I'm having trouble testing it with Jasmine. The code inside the promise handler in the test never executes . The controller: /* global Q */ 'use strict'; angular.module('myModule', ['some.service']) .controller('MyCtrl', ['$scope', 'SomeSvc', function ($scope, SomeSvc) { $scope.getTheData = function (id) { var deferred = Q.defer(); var processedResult = ''; SomeSvc.getData(id) .then

how to mock $window to unit test AngularJS service?

自古美人都是妖i 提交于 2019-12-01 05:39:18
Here is my service: var services = angular.module('amdotcom.services', ['ngResource']); services.factory('homePageRes', ['$resource', '$window', function ($resource, $window) { var wdw = angular.element($window); return $resource('home/index', { height: wdw.height(), width: wdw.width() }); }]); services.factory('homePageLoader', ['homePageRes', '$q', function (homePageRes, $q) { return function () { var delay = $q.defer(); homePageRes.get(function (homePage) { delay.resolve(homePage); }, function () { delay.reject('Unable to fetch home page'); }); return delay.promise; }; }]); Below is my test

Angular 2 Jasmine How to test a function of a component

浪尽此生 提交于 2019-12-01 05:12:56
How do I mock the click event of a function in Angular 2? For my Home Component I have: Home Component import { Component } from '@angular/core'; import { Router } from '@angular/router'; @Component({ moduleId: module.id, templateUrl: 'home.component.html', styleUrls: ['home.component.css'], selector: 'home', }) export class HomeComponent { constructor(private router: Router) { } redirectToUpload() { this.router.navigate(['/upload']); } redirectToAbout() { this.router.navigate(['/about']); } } Home Component spec import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import

Make the component test to have a body or mock Renderer2

拜拜、爱过 提交于 2019-12-01 04:50:40
问题 In one of our component, we use Renderer2 to add and remove some css classes/styles to the body element. To achieve that, we simply do something like: this.renderer.setStyle(document.body, 'padding-left', '10px'); this.renderer.addClass(document.body, 'modal-container--opened'); As soon as we run the tests, we encounter errors: Cannot read property 'add' of undefined Cannot set property 'padding-left' of undefined So it seems angular testBed doesn't create any body element. In our test