jasmine

Angular and Jasmine: How to test requestError / rejection in HTTP interceptor?

三世轮回 提交于 2019-12-24 11:37:28
问题 How would you test this requestError method? angular.module('myApp').factory 'HTTPInterceptor', [ '$rootScope' '$q' '$window' 'LocalStorageService' '$injector' ($rootScope, $q, $window, $injector) -> { request: (config) -> config.headers = config.headers or {} // do stuff with config then config # Return Config requestError: (rejection) -> q.reject(rejection) # Return the promise rejection ... 回答1: Hey its been long since you post this question but I think I have solution for this question

Faking a module in angular 2 test

廉价感情. 提交于 2019-12-24 11:29:21
问题 I have a function in angular 2 service which I would like to test. service.ts upload(){ let file = new Transfer(); file.upload(myfile).then( // my callback ); } I would like to mock Transfer in my test using jasmine . I tried this in my sevice.spec.ts import { TransferMock as Transfer } from '../mocks/mocks' to mock it. But it is not working. This is how my test is instantiated . describe('authentication service' , () => { beforeEach(() => { auth = new Service(<any>new HttpMock(), <any>new

Unit-Testing a service in Controller with Jasmine in AngularJS

北城以北 提交于 2019-12-24 11:25:17
问题 In my Controller I've defined the following service: CrudService.getAllGroups().$promise.then( function (response) { $scope.groups = response; }, function (error) { //error code.. } ); Well, I want to test this service whether it gets a response or not. In test script at first I've defined a function to check whether the service is defined at all. Test code: describe('Ctrl: TestCtrl', function () { beforeEach(module('testApp')); var scope, CrudService, ctrl, backend; beforeEach(inject

Testing directive that uses bootstrap popover

回眸只為那壹抹淺笑 提交于 2019-12-24 10:35:05
问题 I have directive that uses bootstrap's popover. It becomes popover when variable is set: if (newValue.show === true) { element.popover('show'); } How can I make spy test with karma/jasmine tests? I tried this: spyOn(element, 'popover'); it('should call bootstrap method popover', function () { $scope.$apply(function() { $scope.value.show = true; }); expect(element.popover).toHaveBeenCalled() }); But I get error: Expected spy popover to have been called. Error: Expected spy popover to have been

How to generate skeleton using cucumber feature file

久未见 提交于 2019-12-24 09:29:40
问题 We have tried below steps: on node command prompt we tried exciting below commands Npm install -g cucumber Also we tried npm install -g protractor-cucumber cucumber --version Above command opening webstorm editor. We have created feature file(feature/testfeature.feature) Now to generate skeleton we tried running below command on cmd prompt. Cucumber.js It is opening webstorm editor We are not able to see skeleton file Could you please suggest if we are missing anything We should be able to

Protractor takes blank screenshots when “restartBrowserBetweenTests: true” is set

不想你离开。 提交于 2019-12-24 09:22:08
问题 I'm trying to use protractor-jasmine2-html-reporter to take screenshots of my tests as they run, but it appears to be taking them directly after the browser is restarted due to the "restartBrowserBetweenTests" flag in conf.js being set to "true". I need to use that flag to restart the browser because it seems to be the only way to clear the session sufficiently so that subsequent tests can use the sign in page, rather than the application assuming it's the same user and redirecting them to

Intermittent unit-test failure associated with i18next

▼魔方 西西 提交于 2019-12-24 09:06:01
问题 I am trying to unit test my aurelia custom element, which looks like below. // BaseText.ts import { bindable } from "aurelia-framework"; import { BaseI18N } from "aurelia-i18n"; export class BaseText extends BaseI18N { @bindable public value: string; @bindable public i18nKey: string; } // NormalText.ts export class NormalTextCustomElement extends BaseText {} // NormalText.html <template> <span t.bind="i18nKey">${value}</span> </template> Now, I want to test if I change the value of i18nKey ,

Jasmine tests in Resharper don't stop executing

喜欢而已 提交于 2019-12-24 08:18:54
问题 I use Visual Studio 2012 and ReSharper 8.2 to test my JavaScript code. Using QUnit works perfectly so far, when writing Jasmine tests the tests don't stop when the following line is added at the beginning of the file: /// <reference path="../lib/jasmine.js" /> When I remove it, the tests stop soon, as it should be. I would like to keep this line though so VS knows the syntax of the Jasmine commands. It doesn't matter whether I use phantom.js or not. The behaviour is the same. According to

Why does my jasmine tests fail on this directive?

半腔热情 提交于 2019-12-24 08:16:17
问题 I have built an angular directive onInputChange that should fire a callback when the users changes a value of an input by either clicking outside of the input (blur) or hitting ENTER . The directive can be used like: <input type="number" ng-model="model" on-input-change="callback()"/> It uses the following code: app.directive('onInputChange', [ "$parse", function ($parse) { return { restrict : "A", require : "ngModel", link : function ($scope, $element, $attrs) { // var dirName =

Jasmine - How to exclude node_modules from spec coverage

给你一囗甜甜゛ 提交于 2019-12-24 08:08:13
问题 I'm in trouble excluding node_modules files from my spec_files option. This is my jasmine.json config. { "spec_dir": "packages", "spec_files": [ "**/*[sS]pec.js" ], "helpers": [ "helpers/**/*.js" ], "stopSpecOnExpectationFailure": false, "random": true } the spec_dir is a directory with multiple node_projects, each one has their own node_modules folder. I've tried add '!node_modules/**/*[sS]pec.js' on the spec_files array but didn't work. Is that a bug? Because from what i read in the docs