Releases: simonihmig/ember-window-mock
Release 0.7.1
🐛 Bug Fix
- #201 Reset to
doNothingHandler
in tests (@alexlafroscia)
Committers: 1
- Alex LaFroscia (@alexlafroscia)
Release 0.7.0
💥 Breaking Change
- #191 Add compatibility for embroider (@simonihmig)
You now have to importsetupWindowMock
(orreset
) from'ember-window-mock/test-support'
!
🚀 Enhancement
- #191 Add compatibility for embroider (@simonihmig)
📝 Documentation
- #200 Update docs (@simonihmig)
🏠 Internal
- #199 Setup release-it (@simonihmig)
- #198 Update Ember 3.19 (@simonihmig)
Committers: 2
- Simon Ihmig (@simonihmig)
- @dependabot-preview[bot]
Drop node 8, Ember < 3.12
v0.6.0 v0.6.0
Drop node 4
- drops support for node 4
- updated dependencies
- added basic TypeScript defintion
setupWindowMock
- added
setupWindowMock()
to easily setup tests under the new testing APIs including resetting the state. Thanks to @makepanic
Mock even more
- replaces
localStorage
in tests with a mock, same API but ephemeral storage (thanks to @alisdair) - adds a
Proxy
to all nested objects, likewindow.navigator
. This allows to override even read-only properties, likewindow.navigator.userAgent
- fixes support for relative URLs when setting
window.location.href
Import all the things
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
).