jasmine

How to test file upload with Jasmine BDD

我怕爱的太早我们不能终老 提交于 2019-12-04 07:14:42
I'm using jQuery file upload plugin for managing image file uploads. What will be the right way to test image submission with Jasmine. I would take a look at using the helper library Sinon.js. You can mock the XMLHttpRequest object to intercept the post request, and verify that your plugin code is submitting images correctly. In particular, take a look at this part of the Sinon.js documentation: http://sinonjs.org/docs/#server 来源: https://stackoverflow.com/questions/10673001/how-to-test-file-upload-with-jasmine-bdd

Expected Response with status: null null for URL: null to equal 'Project11'

浪尽此生 提交于 2019-12-04 06:54:24
问题 I am using angular7 and doing unit testing in jasmine and karma. And I am facing error - Error: Expected Response with status: null null for URL: null to equal 'Project11'. My packages versions are - "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/jquery": "^3.3.22", "@types/node": "~8.9.4", "codelyzer": "~4.2.1", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~1.4.2",

AngularJS Unit Testing - Various patterns for injecting dependencies

北城余情 提交于 2019-12-04 06:52:11
I'm new to unit testing and am mainly learning from examples that I find. The problem is that I've seen so many different patterns that it's hard to understand what the differences are between them. And how to combine those patterns for various use cases. Below is one such pattern: var $rootScope, $window, $location; beforeEach(angular.mock.module('security.service', 'security/loginModal.tpl.html')); beforeEach(inject(function(_$rootScope_, _$location_) { $rootScope = _$rootScope_; $location = _$location_; })); var service, queue; beforeEach(inject(function($injector) { service = $injector.get

isSelected returns false and isChecked shows compilation error

若如初见. 提交于 2019-12-04 05:45:31
问题 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 回答1: There is nothing called isChecked in Protractor. You can do this by using isSelected. webdriver.WebElement

Can't switch windows during testing by Webdriver JS

佐手、 提交于 2019-12-04 05:26:54
问题 I can't switch windows during my testing by Selenium Webdriver using Jasmine JS. Runner: Protractor JS Platform: Selenium Webdriver on Node.JS Code framework: Jasmine JS The code is below, Please note the second code block: describe('payments', function() { // beforeEach(function() { // browser.ignoreSynchronization = true; // }); // afterEach(function(){ // browser.ignoreSynchronization = false; // }); this.selectWindow = function (index) { browser.driver.wait(function() { return browser

Responsive design testing with PhantomJS

早过忘川 提交于 2019-12-04 05:25:06
I have a javascript application (RequireJS with Backbone ) which I am testing using PhantomJS with Jasmine. After much pain I finally have simple tests running. I am using a test runner based on the one found here run-jasmine.js . My application is responsive in that as the viewport width changes, the widths of various DOM elements will also change. I am aware that I can set the viewport width in 'run-jasmine.js' when I create the 'page' for testing. What I would like to know is.....Are you able to somehow loop through a series of viewport widths in a single test suite. Using 'run-jasmine.js'

Angular & Jasmine Unit Test change event for input[type=“file”]

一个人想着一个人 提交于 2019-12-04 03:50:06
问题 I am trying to go for 100% test coverage, but i can't seem to test the stuff inside this onUploadFile function. ```html template <input type="file" formControlName="theUpload" id="upload" (change)="onUploadFile($event, i, true)"> ```filing.ts file onUploadFile(evt: Event, index: number, isReq: boolean = false): void { const reader = new FileReader(); const target = <HTMLInputElement>evt.target; if (target.files && target.files.length) { const file = target.files[0]; reader.readAsDataURL(file)

Test an Angular2 Pipe that has a constructor method in Jasmine

China☆狼群 提交于 2019-12-04 03:39:46
问题 I am falling at the first hurdle testing an Angular Pipe that has a constructor. My Pipe is as follows: reverse.pipe.ts import { IterableDiffer, IterableDiffers, Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'reverse', pure: false }) export class ReversePipe implements PipeTransform { private cached: Array<any>; private differ: IterableDiffer<Array<any>>; constructor(private differs: IterableDiffers) { this.differ = this.differs.find([]).create(null); } transform(array: Array<any>

Testing postMessage with Jasmine async doesn't work

感情迁移 提交于 2019-12-04 03:17:56
I'm trying to use Jasmine 2.0 to write unit tests for some logic in an AngularJS app, but the logic is inside an event listener. From the controller: window.addEventListener('message', function(e) { if (e.data === "sendMessage()") { $scope.submit(); } }, false); And from the test file: describe("post message", function() { beforeEach(function(done) { var controller = createController(controllerParams); spyOn($scope, 'submit'); window.postMessage('sendMessage()', '*'); done(); }); it('should submit on a sent message', function (done) { expect($scope.submit).toHaveBeenCalled(); done(); }); });

jasmine spy on nested object

眉间皱痕 提交于 2019-12-04 03:03:53
My service object looks like this: var appService = { serviceOne: { get: function(){} }, serviceTwo: { query: function(){} } } I would like to mock appService,something like: expect(appService.serviceTwo.query).toHaveBeenCalled(); How would I go about doing it? OK I got this working with this: appService: { serviceOne: jasmine.createSpyObj('serviceOne', ['get']), serviceTwo: jasmine.createSpyObj('serviceTwo', ['query']) } I hope it is the right way to do. Andreas Köberle Just replace the function with jasmine spies: var appService = { serviceOne: { get: jasmine.createSpy() }, serviceTwo: {