jasmine

AngularJS : Testing factory that returns $http promises

徘徊边缘 提交于 2019-12-02 04:14:12
Trying to test an angular service that returns an $http GET request and the then handler, but I'm not able to test that the logic actually works inside of the then function. Here is a basic, truncated version of the service code: angular.module('app').factory('User', function ($http) { var User = {}; User.get = function(id) { return $http.get('/api/users/' + id).then(function (response) { var user = response.data; user.customProperty = true; return user; }); }; return User; }); And here is the test: beforeEach(module('app')); beforeEach(inject(function(_User_, _$q_, _$httpBackend_, _$rootScope

Angularjs testing (Jasmine) - $http returning 'No pending request to flush'

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 03:48:07
问题 My UserManager service automatically fires a $http POST every hour to refresh the user access token. I'm trying to mock that call to verify that the token is being refreshed, but when I try to flush the $httpbackend I get an error saying 'No pending requests to flush' even though I know that the refresh function has been called (added a console.log just to verify). Either the fact that the function is being called through a setTimeOut is effecting the $httpbackend or I'm missing something

isSelected returns false and isChecked shows compilation error

我的未来我决定 提交于 2019-12-02 03:25:28
let checkBoxXpath = accessPolicyPage.listCheckBoxXpathS + i + accessPolicyPage.listCheckBoxXpathE; //element(by.xpath(checkBoxXpath)).click(); expect(element(by.xpath(checkBoxXpath)).isSelected()).toBeTruthy(); in the above code isSelected returns false and if I replace it by isChecked, it shows error as "property 'ischecked' not found on ElementFinder" How I can overcome this There is nothing called isChecked in Protractor. You can do this by using isSelected. webdriver.WebElement.prototype.isSelected = function() { return this.schedule_( new webdriver.Command(webdriver.CommandName.IS_ELEMENT

getting 404 error when generating allure report in protractor using allure command line tool

好久不见. 提交于 2019-12-02 03:06:44
I am trying to generate allure report in protractor for the first time, To generate allure report I am using jasmine allure reporter:1.0.2 and allure-commandline tool:2.7.0 versions In my conf file I have added the code for generating xml results in a specific folder and then I am using allure-commandline tool to generate html report which gets generated in a folder named "Allure-report" in the project home directory, but now when I open the index.html file generated by using allure-commandline tool then I see 404 error in the different sections of report Further I also tried to run following

Injecting a factory with dots in name

徘徊边缘 提交于 2019-12-02 03:05:47
问题 I need to use the angularjs mock inject method within Jasmine to inject a service with dots in the name. I tried to do add string identifiers but the inject method does not seem to support this. This is not possible: beforeEach(inject(['$rootScope','MyApp.Factories.TestFactory', function ($rootScope, testFactory) { //doSomeThing }])); Is there another way to handle this? 回答1: I haven't tested this, but you can probably get it from the $injector yourself. Something like this: beforeEach(inject

Jasmine test fails running in VS2012 + Resharper + PhantomJS

心已入冬 提交于 2019-12-02 02:43:19
问题 I tried to run a jasmine unit test in resharper 7 in vs2012 but its failing. resharper + phantomjs is running it in autogenerated url which maybe the cause of the failure is there a way to configure the test to use an absolute or a known URL? UPDATE I added js reference in my *spec.js file /// <reference path="../jasmine/jasmine-html.js" /> /// <reference path="../jasmine/jasmine.js" /> /// <reference path="../jasmine/boot.js" /> /// <reference path="../jasmine/console.js" /> /// <reference

Unit Testing Angular Observables

自作多情 提交于 2019-12-02 02:28:56
I am new to testing world and I have just started writing unit tests for an existing Angular 2 code. I have a function confirmDelete which returns Obserable<boolean> and internally uses ConfirmationService of PrimeNG to get user's feedback on a popup. Definition of the function is given below: confirmDelete(): Observable<boolean> { let confirmObservable = Observable.create((observer: Observer<boolean>) => { this.confirmationService.confirm({ header: 'Delete Confirmation', message: 'Do you really want to delete this record?', accept: () => { observer.next(true); observer.complete(); }, reject:

Injecting a factory with dots in name

大憨熊 提交于 2019-12-02 02:19:26
I need to use the angularjs mock inject method within Jasmine to inject a service with dots in the name. I tried to do add string identifiers but the inject method does not seem to support this. This is not possible: beforeEach(inject(['$rootScope','MyApp.Factories.TestFactory', function ($rootScope, testFactory) { //doSomeThing }])); Is there another way to handle this? I haven't tested this, but you can probably get it from the $injector yourself. Something like this: beforeEach(inject(function($rootScope,$injector) { var testFactory = $injector.get('MyApp.Factories.TestFactory'); /

I am finding trouble using log4js-protractor-appender

柔情痞子 提交于 2019-12-02 02:17:41
My log4js.js file code 'use strict'; var log4js = require('log4js'); var log4jsGen = { getLogger: function getLogger() { log4js.loadAppender('file'); log4js.addAppender(log4js.appenders.file('./ApplicationLogs.log'), 'logs'); var logger = log4js.getLogger('logs'); return logger; } }; module.exports = log4jsGen; My conf.js file(specific to appender section only) "appenders": [{ "type": "log4js-protractor-appender", "append": 'false', "maxLogSize": 20480, "backups": 3, "category": "relative-logger" }], Problem: 1) IS there a way that the logs will get overwritten in each run. 2) Why log4js

Jasmine test fails running in VS2012 + Resharper + PhantomJS

自作多情 提交于 2019-12-02 01:56:17
I tried to run a jasmine unit test in resharper 7 in vs2012 but its failing. resharper + phantomjs is running it in autogenerated url which maybe the cause of the failure is there a way to configure the test to use an absolute or a known URL? UPDATE I added js reference in my *spec.js file /// <reference path="../jasmine/jasmine-html.js" /> /// <reference path="../jasmine/jasmine.js" /> /// <reference path="../jasmine/boot.js" /> /// <reference path="../jasmine/console.js" /> /// <reference path="Player.js" /> /// <reference path="Song.js" /> /// <reference path="SpecHelper.js" /> and it fixed