Skip to content

Releases: simonihmig/ember-window-mock

Import all the things

13 Feb 13:50
Compare
Choose a tag to compare

This is a general overhaul of the architecture and a breaking change!

Before this change the window object (the original global or the mocked version) would be accessed as a service. But to enable this.get('window').location to work, the service was not extending form Ember.Service but instead was directly exposing the window object. This required a special initializer to register the service, with the instantiate: false flag, as Ember's DI expects a valid factory (.create()) otherwise. This had the drawback that you could not lookup the service just by Ember's naming conventions, but instead you need an initializer (for the app itself or acceptance tests), or have an explicit mockWindow() call (for integration tests). Failing to call the latter would cause any integration tests that includes a component (or any other object) that injects the service to fail with an unknown service exception. See #23.

The very first implementation of this addon was using Ember's DI to register a different service (the mock) depending on the environment (test). But the later optimization to not include the mock code into production was relying on a different technique: the mock code would go into the addon-test-support tree and thus into test-support.js, and would simply "override" the AMD module with the same name. So effectively Ember's DI was not really used to switch implementations.

This release changes the architecture to not rely on a service anymore. Instead it yields the (original or mocked in tests) window object as a direct import:

import window from 'ember-window-mock';

It also exposes a reset function to reset the state of the object across tests (e.g. window.location.href).