jasmine

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

血红的双手。 提交于 2019-12-01 09:01:26
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(function (result) { //process data processedResult = 'some stuff'; deferred.resolve(processedResult); }) .fail

Custom message on wait timeout error

喜夏-厌秋 提交于 2019-12-01 08:34:41
问题 From time to time I'm using "Expected Conditions" feature introduced in protractor 1.7. Use case : var EC = protractor.ExpectedConditions; browser.wait(EC.visibilityOf(header.displayName), 10000); where header is a Page Object. If header.displayName would not become visible in 10 seconds, an error would be thrown: [firefox #4] 2) Describe description here [firefox #4] Message: [firefox #4] Error: Wait timed out after 10082ms [firefox #4] Stacktrace: [firefox #4] Error: Wait timed out after

Getting error while using Jasmine with AngularJS

孤街浪徒 提交于 2019-12-01 08:26:19
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) { ##....controller content....## } ]); SpecRunner.html <script type="text/javascript" src="../lib/angular

Angular 2 rc5 , unit testing issue with pipes that use injection

给你一囗甜甜゛ 提交于 2019-12-01 07:35:03
问题 I am using angular2 rc 5, I have written a custom pipe that fetches value from a json. The custom pipe : literal.pipe.ts looks like : import {Pipe, PipeTransform, Inject} from '@angular/core'; import {MessageService} from '../service/message.service'; @Pipe({ name: 'literalString', pure: false }) export class LiteralPipe implements PipeTransform{ private messageBundle:any; private request:any; constructor(private _messageService: MessageService){ this._messageService = _messageService; this

protractor-jasmine2-html-reporter doesn't consolidate results for all test when tests are shared using 'shardTestFiles': true in conf file

南笙酒味 提交于 2019-12-01 07:28:05
问题 Recently we have configured our e2e-tests to be on Jenkins & soon we realized that we have to use shared test files: true options as complete suite run is taking very long time for us peeking 9-10hrs on daily basis. but when we configured below two options in conf file. tests are running fine but final report displays only the last specs run results in save path. consolidate all options is not giving the full reports. please find our conf file details. any help will be appreciated. Edit the

Anyway to use OR in expects for Protractor

China☆狼群 提交于 2019-12-01 07:15:24
问题 It is possible to do a x.toEqual('hello').or.toEqual('bye') ? I want to be able to do Expects that have multiple correct possibilities. 回答1: You can always do an if statement that returns a boolean and then check if that boolean is true. var test = false; if(x=='hello' || x=='bye'){ test = true; } expect(test).toEqual(true); 来源: https://stackoverflow.com/questions/24434826/anyway-to-use-or-in-expects-for-protractor

Unit test angular right-click directive

删除回忆录丶 提交于 2019-12-01 07:08:17
I want to write a Jasmine unit test for an AngularJS directive. The directive simply binds a contextmenu event handler function to the element: var myDirectives = angular.module('myApp.directives', []); myDirectives.directive('myRightClick', ['$parse', function ($parse) { return function (scope, element, attrs) { var fn = $parse(attrs.myRightClick); element.bind('contextmenu', function (event) { scope.$apply(function () { event.preventDefault(); fn(scope, { $event: event }); }); }); }; }]); <div my-right-click="myFunction"></div> Unit test: describe('Unit Test Directives', function () { var

Jasmine and Requirejs in Resharper 7

蹲街弑〆低调 提交于 2019-12-01 06:39:42
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? 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 references! /// <reference path="~/Scripts/require.js"/> /// <reference path="../code/sut.js" /> describe(

Location reload in Jasmine

独自空忆成欢 提交于 2019-12-01 06:30:19
I'm really not sure how to approach testing this? (spyOn?) function reloadPage() { $('#logo').click(function() { location.reload(); }) } Any advice would be great! The reason you may be unsure about how to test this piece of code is because it's doing 2 different things and you should break it up into smaller chunks. I see two distinct functions here: click event handling reload page So why not break up the logic like so? function reloadPage() { location.reload(); } function bindEvents() { $('#logo').click(reloadPage); } Now you can test them separately using Spies: describe('when the logo is

Make the component test to have a body or mock Renderer2

ε祈祈猫儿з 提交于 2019-12-01 06:27:19
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 configuration, how to create a mocked body element? So we can run our tests against that element and see if