Skip to content

Commit 2b2372c

Browse files
committed
fix: ensure stubService returns reference to the service
1 parent f6f3721 commit 2b2372c

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ import td from "testdouble";
2525
import { stubService } from "ember-cli-testdouble/test-support";
2626

2727
test("verifying a method invocation", function(assert) {
28-
assert.expect(0); // Won't actually use `assert` in this test
28+
// `stubService` returns a reference to the servive
29+
let someStubbedService = stubService("some-service");
2930

30-
stubService("some-service");
31-
32-
let someService = this.owner.lookup("service:some-service");
33-
someService.method();
31+
// Do something that would call `method()` on the service
3432

3533
td.verify(someService.method()); // Passes!
3634
});

addon-test-support/stub-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function stubService() {
3535
let [name] = arguments;
3636
let { owner } = getContext();
3737

38-
replace(owner, name);
38+
return replace(owner, name);
3939
} else {
4040
throw new Error("Unexpected number of arguments");
4141
}

tests/unit/test-support/stub-service-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ module("Test Helpers | stub-service", function(hooks) {
1818

1919
module("invoking without `hooks`", function(hooks) {
2020
hooks.beforeEach(function() {
21-
stubService("to-stub");
21+
this.service = stubService("to-stub");
2222
});
2323

2424
test("it can replace a service", function(assert) {
2525
let service = this.owner.lookup("service:to-stub");
2626
service.method();
2727

2828
assert.verify(service.method());
29+
assert.equal(
30+
service,
31+
this.service,
32+
"Returns a references to the stubbed service"
33+
);
2934
});
3035
});
3136
});

0 commit comments

Comments
 (0)