jasmine

How do I include lodash in my protractor test specs?

梦想的初衷 提交于 2019-12-06 03:43:21
I want to use lodash functions in my protractor spec, I'm using _.forEach() to fill a form with values. How do I get lodash into my protractor script so that I can use it? I'm not asking how to use it in my app, but in the actual running protractor scripts You can use the native Array.forEach(). If you need lodash do this: Get the node dependency. npm install lodash --save-dev Then use it in your test. var _ = require('lodash'); describe('foo', function() { it('should do stuff', function() { _.each(); }); }) 来源: https://stackoverflow.com/questions/25467600/how-do-i-include-lodash-in-my

Stack trace for Jasmine test with the Resharper 7 test runner

左心房为你撑大大i 提交于 2019-12-06 03:19:56
How do you get the Resharper 7 test runner to show the stacktrace for Jasmine tests. My setup is Resharper 7 (build in Jasmine) testrunner and PhantomJs. When executing any failing test the error message always ends with: Exception doesn't have a stacktrace In the 1.6 "Lavender" version of Phantom has added the feature to print the stacktrace when an error occurs. To replicate this just create a mytest.js file and add the following code to it: describe("A suite", function() { it("contains spec with an expectation", function() { expect(true).toBe(false); }); }); Sorry, I don't use Resharper,

Protractor - Page Object is not updating when the DOM elements are changed

雨燕双飞 提交于 2019-12-06 03:15:58
I am testing a SPA built with angular.js and im using Page Objects pattern to write my tests. In the app we have a number of lists that will be updated. For example there is a list of attachments that will update when ever attachments are added/removed. To add an attachment we have a modal window and when we upload a file and click ok. The file uploads and the lists update. I have written 2 page objects, one for the upload modal window and the other one for the preview of the attachment list. In my tests i first get the current count of the attachments then i click on a button to activate the

Running tests .mjs / ESM on Node using Jasmine or any other alternative

拜拜、爱过 提交于 2019-12-06 03:10:56
问题 My Node-based project is implemented using native ES module support on Node thanks to the --experimental-modules CLI switch (i.e. node --experimental-modules ). Obviously, when I run a spec using Jasmine node --experimental-modules ./node_modules/jasmine/bin/jasmine I get the following error: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module Is it ever possible to use Jasmine using ES modules in Node? If not, is there any alternative to don't use a framework (e.g. running tests with

How to deal with sessionStorage locally in FF (for testing)

别说谁变了你拦得住时间么 提交于 2019-12-06 02:54:31
I'm trying to write tests for all my JS, and the tests (I'm using Jasmine) are run locally in the browser. Due to security restraints(?) sessionStorage does not work locally (viewing file:///... in the browser) in Firefox. Quick example: window.sessionStorage.setItem('foo', 'bar'); This gives "Error: Operation is not supported". I tried overriding window.sessionStorage with my own mock methods, but with no luck. The only solution I have at the moment is to put everything related to sessionStorage inside a try/catch block. Any suggestions for how to best handle this issue? Object.defineProperty

Jasmine spyOn - method does not exist in jQuery anonymous function

痞子三分冷 提交于 2019-12-06 02:36:04
Have searched for the answer to this problem on SO and other forums. Didn't find solution. I'm running into a problem where Jasmine cannot find a function inside of a jQuery code block, whether the Jasmine code is inside the jQuery function or not. $(function() { function foo(param1, param2) { // some code } describe("Foo function", function () { spyOn(window, 'foo'); foo(1, 2); it("Should be found by Jasmine", function(){ expect(window.foo).toHaveBeenCalled(); }); }); }); Error: foo() method does not exist I have also tried spyOn($, 'foo') , spyOn($.fn, 'foo') and others. Also, the following

AngularJS test - inject $location causes error

半腔热情 提交于 2019-12-06 01:52:55
So this one is driving me crazy, whenever i try to inject $location to one of my tests i get the following error: TypeError: undefined is not a function at $LocationProvider.$get (bower_components/angular/angular.js:11053:34) at Object.invoke (bower_components/angular/angular.js:4118:17) at bower_components/angular/angular.js:3936:37 at getService (bower_components/angular/angular.js:4077:39) at Object.invoke (bower_components/angular/angular.js:4109:13) at Object.workFn (bower_components/angular-mocks/angular-mocks.js:2159:20) Error: Declaration Location at window.inject.angular.mock.inject

Protractor closing current tab

送分小仙女□ 提交于 2019-12-06 01:24:53
I have a non-angular page where I need to click on 2 links. When clicking on one of the link that automatically opens in a new tab. Now I switch to new tab and set the browser.ignoreSynchronization = false because the newly opened tab is a angular window; and call one of my test. Once verified. I want to close the current tab and go back to the non-angular page to click on link #2 which would again open in a new tab. I tried window.close but i am getting window is undefined. I used browser.window and even that is not working. Please advise element(by.id('trMyUrl')); browser.getAllWindowHandles

Flushing successful mock POST request using Jasmine does not execute the AngularJS success function

…衆ロ難τιáo~ 提交于 2019-12-06 00:47:13
This is my AngularJS post.js : angular.module("PostPageApp", ["BaseApp"]) .controller("MainCtrl", ["$http", "$window", "BaseService", function($http, $window, BaseService) { var self = this; self.add = function() { BaseService.add.post(self.post, function() { self.cerrorMessages = BaseService.cerrorMessages; }); }; }]); This is base.js : angular.module("BaseApp", []) .config(['$httpProvider', function($httpProvider) { $httpProvider.defaults.xsrfCookieName = 'csrftoken'; $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; }]) .config(['$locationProvider', function($locationProvider){

Mock AngularFireAuth When Unit Testing an Angular Service

柔情痞子 提交于 2019-12-06 00:01:48
I have an authService which when instantiated subscribes to AngularFireAuth 's Observable authState and sets the services' internal (private) property authState . So I can unit test authService I highjack the services' internal authState with Reflect.get/set in my test specs so I can control its value. The problem is of course authService is still subscribing to AngularFireAuth 's Observable authState during its instantiation and I don't want, nor need it to. I presume I need to mock out AngularFireAuth which fakes a subscription and doesn't actually communicate to Firebase? New to unit tests