diff --git a/README.md b/README.md index efff2f7..17dec6e 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,11 @@ Included is a function that can replace a service with one stubbed using [`td.ob import td from "testdouble"; import { stubService } from "ember-cli-testdouble/test-support"; -test("verifying a method invocation", function(assert) { - assert.expect(0); // Won't actually use `assert` in this test +test("verifying a method invocation", function() { + // `stubService` returns a reference to the servive + let someStubbedService = stubService("some-service"); - stubService("some-service"); - - let someService = this.owner.lookup("service:some-service"); - someService.method(); + // Do something that would call `method()` on the service td.verify(someService.method()); // Passes! }); diff --git a/addon-test-support/stub-service.js b/addon-test-support/stub-service.js index 8283547..13efb18 100644 --- a/addon-test-support/stub-service.js +++ b/addon-test-support/stub-service.js @@ -35,7 +35,7 @@ export default function stubService() { let [name] = arguments; let { owner } = getContext(); - replace(owner, name); + return replace(owner, name); } else { throw new Error("Unexpected number of arguments"); } diff --git a/tests/unit/test-support/stub-service-test.js b/tests/unit/test-support/stub-service-test.js index 911b4ec..fea8e89 100644 --- a/tests/unit/test-support/stub-service-test.js +++ b/tests/unit/test-support/stub-service-test.js @@ -18,7 +18,7 @@ module("Test Helpers | stub-service", function(hooks) { module("invoking without `hooks`", function(hooks) { hooks.beforeEach(function() { - stubService("to-stub"); + this.service = stubService("to-stub"); }); test("it can replace a service", function(assert) { @@ -26,6 +26,11 @@ module("Test Helpers | stub-service", function(hooks) { service.method(); assert.verify(service.method()); + assert.equal( + service, + this.service, + "Returns a references to the stubbed service" + ); }); }); });