Skip to content

Commit

Permalink
Merge pull request #425 from MrChocolatine/patch-1
Browse files Browse the repository at this point in the history
Unregister Services before they are registered
  • Loading branch information
simonihmig authored Oct 17, 2024
2 parents 65294cd + 71e831a commit 281cb0f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/twenty-worms-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"ember-browser-services": patch
"test-app": patch
---

Unregister services before they are registered in `setupBrowserFakes()`

Fixes https://github.com/CrowdStrike/ember-browser-services/issues/413
5 changes: 5 additions & 0 deletions ember-browser-services/src/test-support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,24 @@ export function setupBrowserFakes(hooks: NestedHooks, options: Fakes): void {
if (options.window) {
let service = maybeMake(options.window, window);

owner.unregister('service:browser/window');
owner.register('service:browser/window', service);
}

if (options.document) {
let service = maybeMake(options.document, window.document);

owner.unregister('service:browser/document');
owner.register('service:browser/document', service);
}

if (options.localStorage) {
owner.unregister('service:browser/local-storage');
owner.register('service:browser/local-storage', FakeLocalStorageService);
}

if (options.sessionStorage) {
owner.unregister('service:browser/session-storage');
owner.register(
'service:browser/session-storage',
FakeSessionStorageService
Expand All @@ -62,6 +66,7 @@ export function setupBrowserFakes(hooks: NestedHooks, options: Fakes): void {
if (options.navigator) {
let service = maybeMake(options.navigator, window.navigator);

owner.unregister('service:browser/navigator');
owner.register('service:browser/navigator', service);
}
});
Expand Down
13 changes: 13 additions & 0 deletions test-app/app/instance-initializers/lookup-browser-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { assert } from '@ember/debug';

import type ApplicationInstance from '@ember/application/instance';

export function initialize(application: ApplicationInstance) {
const windowService = application?.lookup('service:browser/window');

assert('Expected to have the window service', windowService);
}

export default {
initialize,
};

0 comments on commit 281cb0f

Please sign in to comment.