From fb5b3d90ca7c76888802be65649acbe836b2a9d8 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:41:35 -0400 Subject: [PATCH] Add getService --- test-app/tests/acceptance/get-service-test.ts | 15 +++++++++++++++ test-support/src/container/get-service.ts | 13 +++++++++++++ test-support/src/index.ts | 1 + 3 files changed, 29 insertions(+) create mode 100644 test-app/tests/acceptance/get-service-test.ts create mode 100644 test-support/src/container/get-service.ts diff --git a/test-app/tests/acceptance/get-service-test.ts b/test-app/tests/acceptance/get-service-test.ts new file mode 100644 index 0000000..260254c --- /dev/null +++ b/test-app/tests/acceptance/get-service-test.ts @@ -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); + }); +}); diff --git a/test-support/src/container/get-service.ts b/test-support/src/container/get-service.ts new file mode 100644 index 0000000..3367b28 --- /dev/null +++ b/test-support/src/container/get-service.ts @@ -0,0 +1,13 @@ +import type { Registry as ServiceRegistry } from '@ember/service'; +import { getContext } from '@ember/test-helpers'; + +export function getService( + name: ServiceName, +): ServiceRegistry[ServiceName] { + const context = getContext(); + const owner = context.owner; + + const service = owner.lookup(`service:${name}`); + + return service; +} diff --git a/test-support/src/index.ts b/test-support/src/index.ts index b863760..5674828 100644 --- a/test-support/src/index.ts +++ b/test-support/src/index.ts @@ -1 +1,2 @@ export { visitAllLinks } from './routing/visit-all.ts'; +export { getService } from './container/get-service.ts';