Error: supportsScrollBehavior is not declared configurable

It is not possible anymore to spy on individually exported functions. https://github.com/jasmine/jasmine/issues/1414 There are some workarounds that might work, but there isn’t a “works for all” solution. Quoting from above link: Actually setting “module”: “commonjs” in tsconfig.json for tests fixes this issue and you can use spyOn again. For me, this didn’t work. Jasmine needs … Read more

How to debug timed out waiting for asynchronous Angular tasks? Failure to find elements on angular page occurring

In the following I list a set of potential causes and possibilities to fix/resolve them. How does AngularJS and Angular(2) Work / What can I check in the Browser Dev Mode I can’t explain it as well as Andrey Agibalov in his Blog here, so check it out (also for developers). Basically, the objects required … Read more

How to test a function which has a setTimeout with jasmine?

The overall approach varies based on your Jasmine version. Jasmine 1.3 You can use waitsFor: it( “Disable all submit buttons”, function() { // Get a button var $button = $( ‘#ai1ec_subscribe_users’ ); // Call the function utility_functions.block_all_submit_and_ajax( $button.get(0) ); // Wait 100ms for all elements to be disabled. waitsFor(‘button to be disabled’, function(){ var found … Read more

mocking window.location.href in Javascript

The best way to do this is to create a helper function somewhere and then mock that: var mynamespace = mynamespace || {}; mynamespace.util = (function() { function getWindowLocationHRef() { return window.location.href; } return { getWindowLocationHRef: getWindowLocationHRef } })(); Now instead of using window.location.href directly in your code simply use this instead. Then you can … Read more

How do I focus on one spec in jasmine.js?

When using Karma, you can enable only one test with fit or fdescribe (iit and ddescribe in Jasmine before 2.1). This only runs Spec1: // or “ddescribe” in Jasmine prior 2.1 fdescribe(‘Spec1’, function () { it(‘should do something’, function () { // … }); }); describe(‘Spec2’, function () { it(‘should do something’, function () { … Read more

Timed out waiting for asynchronous script result while executing protractor scripts with appium

1. Regarding with route check In case after first spec, user got logged in and the route changed. Make sure all are navigated before any test executed. expect(browser.getCurrentUrl()).toContain(‘#/the_route_of_logged_in’); // ‘#/’ is just illustration. You can remove it to make it shorter // => like this …toContain(‘the_route_of_logged_in’); 2. Regarding with click on tutorial browser.wait(EC.elementToBeClickable(tutorial), 10000); Do … Read more

How to reuse beforeEach/afterEach in Jasmine JS?

I think this is partially examined in this blog post and also answered here but i’m adding an adapted answer for your example: Reusable code: function sharedSetup(startPage) { beforeEach(function() { login_as_admin(); browser().navigateTo(startPage); }); afterEach(function() { logout(); }); }; How to use it: describe(‘Services Page’, function() { sharedSetup(‘/services’); it(‘Some test for services page’, function() {}); }); … Read more

Updating input html field from within an Angular 2 test

You’re right that you can’t just set the input, you also need to dispatch the ‘input’ event. Here is a function I wrote earlier this evening to input text: function sendInput(text: string) { inputElement.value = text; inputElement.dispatchEvent(new Event(‘input’)); fixture.detectChanges(); return fixture.whenStable(); } Here fixture is the ComponentFixture and inputElement is the relevant HTTPInputElement from the … Read more