Skip to content

Commit

Permalink
fix: ensure stubService returns reference to the service
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlafroscia committed Jul 17, 2018
1 parent f6f3721 commit 0b73f48
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
});
Expand Down
2 changes: 1 addition & 1 deletion addon-test-support/stub-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/test-support/stub-service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ 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) {
let service = this.owner.lookup("service:to-stub");
service.method();

assert.verify(service.method());
assert.equal(
service,
this.service,
"Returns a references to the stubbed service"
);
});
});
});

0 comments on commit 0b73f48

Please sign in to comment.