jasmine

Set element height in PhantomJS

心已入冬 提交于 2019-11-30 08:20:47
问题 How do I set element height while testing in PhantomJS? I'm testing on Karma using Jasmine framework and running on PhantomJS headless browser. I'm trying to test an AngularJS directive concerned with "infinite scrolling" (automated loading of items when user scrolls near to the bottom of the container element). I'm not using jQuery, nor do I wish to (unless there's no other way). I'm using .clientHeight , .scrollTop , and .scrollHeight properties. My directive works as expected, at least in

Spying on jQuery $('…') selector in jasmine

无人久伴 提交于 2019-11-30 08:20:11
问题 When it comes to spying on jQuery functions (e.g. bind , click , etc) it is easy: spyOn($.fn, "bind"); The problem is when you want to spy on $('...') and return defined array of elements. Things tried after reading other related answers on SO: spyOn($.fn, "init").andReturn(elements); // works, but breaks stuff that uses jQuery selectors in afterEach(), etc spyOn($.fn, "merge").andReturn(elements); // merge function doesn't seem to exist in jQuery 1.9.1 spyOn($.fn, "val").andReturn(elements);

How to mock File in javascript?

纵饮孤独 提交于 2019-11-30 07:55:55
I'm developing some small project to exercise my TDD skills. The project consists of an audio player which has the ability to drag'n'drop files in a playlist. I'm using Jasmine as a testing framework. The problem I faced is that I can't mock javascript files to test my file upload functionality. I tried to create a File like this: new File(new Blob(), "name"); but Chrome does not allow creating files manually. File's constructor is illegal to use. I found a solution with grunt.js which consists of returning some files from grunt, but I don't really wanna use server-side for such a small test

How can I confirm what version of Jasmine I'm using?

旧时模样 提交于 2019-11-30 07:50:13
If I recall there is a command in Jasmine that will log the exact version of Jasmine I'm running to the console, but I can't remember what it is. I am positive I have seen this before somewhere, and now that I actually need it I can't find it anywhere. Does anyone know what it is? Edit: The posted solution of using jasmine.getEnv().versionString() isn't working - to any mods reading this, would fixing that issue be better to start as a new question, or continue here? To simply log the version number try: if (jasmine.version) { //the case for version 2.0.0 console.log('jasmine-version:' +

How do we clear spy programmatically in Jasmine?

不想你离开。 提交于 2019-11-30 07:47:43
How do we clear the spy in a jasmine test suite programmatically? Thanks. beforeEach(function() { spyOn($, "ajax").andCallFake(function(params){ }) }) it("should do something", function() { //I want to override the spy on ajax here and do it a little differently }) I'm not sure if its a good idea but you can simply set the isSpy flag on the function to false: describe('test', function() { var a = {b: function() { }}; beforeEach(function() { spyOn(a, 'b').andCallFake(function(params) { return 'spy1'; }) }) it('should return spy1', function() { expect(a.b()).toEqual('spy1'); }) it('should return

How to have different return values for multiple calls on a Jasmine spy

瘦欲@ 提交于 2019-11-30 07:47:33
Say I'm spying on a method like this: spyOn(util, "foo").andReturn(true); The function under test calls util.foo multiple times. Is it possible to have the spy return true the first time it's called, but return false the second time? Or is there a different way to go about this? You can use spy.and.returnValues (as Jasmine 2.4). for example describe("A spy, when configured to fake a series of return values", function() { beforeEach(function() { spyOn(util, "foo").and.returnValues(true, false); }); it("when called multiple times returns the requested values in order", function() { expect(util

Can webpack 4 modules be configured as to allow Jasmine to spy on their members?

穿精又带淫゛_ 提交于 2019-11-30 07:25:37
问题 I've been unable to get my test jasmine test suite running with webpack 4. After upgrading webpack, I get the following error for almost every test: Error: <spyOn> : getField is not declared writable or has no setter This is due to a common pattern we use to create spys for simple functions is: import * as mod from 'my/module'; //... const funcSpy = spyOn(mod, 'myFunc'); I've played around with module.rules[].type but none of the options seem to do the trick. This webpack GH issue indicates

How to mock an AJAX request?

北城以北 提交于 2019-11-30 07:14:58
问题 What is the simplest way to modify scenarios.js to mock an AJAX request during an end-to-end test? <!doctype html> <html lang="en" ng-app="myApp"> <head> <meta charset="utf-8"> <title>My Test AngularJS App</title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular-resource.min.js"></script> <script language="javascript" type="text/javascript"> angular.module('myApp', ['ngResource

How to write Protractor test scripts using Typescript along with Jasmine framework in Visual studio Code?

好久不见. 提交于 2019-11-30 07:01:13
问题 My project is going from standalone to Web, Our new WebSite is getting created in AngularJS so Protractor is the tool selected for Test Automation. I want to Integrate Typescript with dependencies of Jasmine and Node so that I don't get errors such as cannot find name Describe cannot find name it cannot find name Expect Can Anyone tell me how to add Jasmine and Protractor dependencies, so that when I hit ctrl + space i'll get all options available. I have installed Typescript. And I am

Scroll down to an element with protractor

强颜欢笑 提交于 2019-11-30 06:55:52
I have an element on the page that I'm testing that I have to scroll down to be visible. When I execute my test, I get Element is not clickable at point (94, 188) for example. I tried the following: dvr.executeScript('window.scrollTo(0,250);'); But it didn't work. Does anyone know how this works? i think this is helpful to you: dvr.executeScript('window.scrollTo(94,188);').then(function() { element(by.<<here your button locator>>).click(); }) your webdriver is unable to read that point (1254,21),the reason is your protractor browser unable to cover the full of page what do you want to test,