Skip to content

Commit

Permalink
Add getService
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Mar 13, 2024
1 parent f939693 commit fb5b3d9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test-app/tests/acceptance/get-service-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit } from '@ember/test-helpers';

import { getService } from '@universal-ember/test-support';

module('getService', function (hooks) {
setupApplicationTest(hooks);

test('gets the service', async function (assert) {
const router = getService('router');

assert.ok(router);
});
});
13 changes: 13 additions & 0 deletions test-support/src/container/get-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Registry as ServiceRegistry } from '@ember/service';
import { getContext } from '@ember/test-helpers';

export function getService<ServiceName extends keyof ServiceRegistry>(
name: ServiceName,
): ServiceRegistry[ServiceName] {
const context = getContext();
const owner = context.owner;

const service = owner.lookup(`service:${name}`);

return service;
}
1 change: 1 addition & 0 deletions test-support/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { visitAllLinks } from './routing/visit-all.ts';
export { getService } from './container/get-service.ts';

0 comments on commit fb5b3d9

Please sign in to comment.