samedi 17 juin 2017

What is the testability problems of window in javascripts which is solved in $windows

As a novice start to learn angularjs and with a weak javascript background, could someone give some illustrative examples and explain further what is the idea/purpose behind $window, a built-in service in AngularJS?

Reading a book "AngularJS up and running", but do not understand its explanation:

The $window service in AngularJS is nothing but a wrapper around the global window object. The sole reason for its existence is to avoid global state, especially in tests. Instead of directly working with the window object, we can ask for and work with $window. In the unit tests, the $window service can be easily mocked out (available for free with the AngularJS mocking library).

and then visit official documention of AngularJS: http://ift.tt/1iD2D7J$window

A reference to the browser's window object. While window is globally available in JavaScript, it causes testability problems, because it is a global variable. In AngularJS we always refer to it through the $window service, so it may be overridden, removed or mocked for testing.

what is the above mentioned global problem for testing? Thanks

Aucun commentaire:

Enregistrer un commentaire