Skip to content

Commit d09b653

Browse files
authored
Merge pull request #176 from xg-wang/patch-1
Remove `this.setupRouter` from tests
2 parents d002ef7 + 3b339e4 commit d09b653

File tree

1 file changed

+7
-37
lines changed

1 file changed

+7
-37
lines changed

src/markdown/tutorial/part-2/09-route-params.md

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -114,43 +114,9 @@ Alright, we have just one more step left here: updating the tests. We can add an
114114
git add tests/integration/components/rental-test.js
115115
```
116116
117-
If we run the tests in the browser, everything should...
117+
If we run the tests in the browser, everything should just pass!
118118
119-
```run:screenshot width=1024 height=768 retina=true filename=fail.png alt="The test failed"
120-
visit http://localhost:4200/tests?nocontainer&nolint&deterministic
121-
wait #qunit-banner.qunit-fail
122-
```
123-
124-
...wait a minute, our tests didn't pass!
125-
126-
Well, it's about time that we ran into something that didn't Just Work™ on the first try! This is the *advanced* part of the tutorial after all. 😉
127-
128-
Component tests (like the one we have here) do not set up the router by default, because it's usually not necessary. In this specific case, however, we have a `<LinkTo>` in our component that is relying on the router to generate its URLs.
129-
130-
In this situation, we essentially need to *specifically* opt-in to explicitly use our router in our component test. We can do this by calling `setupRouter()` in our `beforeEach` hook, which will set up the router before each test.
131-
132-
```run:file:patch lang=js cwd=super-rentals filename=tests/integration/components/rental-test.js
133-
@@ -8,2 +8,6 @@
134-
135-
+ hooks.beforeEach(function () {
136-
+ this.owner.setupRouter();
137-
+ });
138-
+
139-
test('it renders information about a rental property', async function (assert) {
140-
```
141-
142-
> Zoey says...
143-
>
144-
> As its name implies, the `beforeEach` hook runs *once* before each `test` function is executed. This hook is the ideal place to set up anything that might be needed by all test cases in the file. On the other hand, if you need to do any cleanup after your tests, there is an `afterEach` hook!
145-
146-
Setting up our router before each test function is executed will allow us to properly test that the URLs generated by `<LinkTo>` are exactly what we expect them to be.
147-
148-
```run:command hidden=true cwd=super-rentals
149-
ember test --path dist
150-
git add tests/integration/components/rental-test.js
151-
```
152-
153-
```run:screenshot width=1024 height=768 retina=true filename=pass.png alt="Tests are passing after our modifications"
119+
```run:screenshot width=1024 height=768 retina=true filename=pass.png alt="Tests are passing"
154120
visit http://localhost:4200/tests?nocontainer&nolint&deterministic
155121
wait #qunit-banner.qunit-pass
156122
```
@@ -358,7 +324,11 @@ Now that we have this template in place, we can add some tests for this new comp
358324
});
359325
```
360326
361-
We can again use the `beforeEach` hook that we learned about earlier, which allows us to have two tests that each focus on a different, single aspect of the component, while also sharing some boilerplate code! This feels similar to other tests that we've already written&mdash;hopefully it feels easy, too!
327+
We can use the `beforeEach` hook to share some boilerplate code, which allows us to have two tests that each focus on a different, single aspect of the component. This feels similar to other tests that we've already written&mdash;hopefully it feels easy, too!
328+
329+
> Zoey says...
330+
>
331+
> As its name implies, the `beforeEach` hook runs *once* before each `test` function is executed. This hook is the ideal place to set up anything that might be needed by all test cases in the file. On the other hand, if you need to do any cleanup after your tests, there is an `afterEach` hook!
362332
363333
```run:command hidden=true cwd=super-rentals
364334
ember test --path dist

0 commit comments

Comments
 (0)