How to Unit Test Isolated Scope Directive in AngularJS

See angular element api docs. If you use element.scope() you get the element’s scope that you defined in the scope property of your directive. If you use element.isolateScope() you get the entire isolated scope. For example, if your directive looks something like this : scope : { myScopeThingy : ‘=’ }, controller : function($scope){ $scope.myIsolatedThingy … 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

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

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

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

How to spyOn a value property (rather than a method) with Jasmine

In February 2017, they merged a PR adding this feature, they released in April 2017. so to spy on getters/setters you use: const spy = spyOnProperty(myObj, ‘myGetterName’, ‘get’); where myObj is your instance, ‘myGetterName’ is the name of that one defined in your class as get myGetterName() {} and the third param is the type … Read more

tech