You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update tutorial to use assert.strictEqual in place of assert.equal to pass eslint-plugin-qunit (#197)
* Update tutorial to use `assert.strictEqual` in place of `assert.equal`
to pass eslint-plugin-qunit
Co-authored-by: Godfrey Chan <godfreykfc@gmail.com>
Looking at the failure closely, the problem seems to be that the component had captured `http://localhost:4200/tests` as the "current page's URL". The issue here is that the `<ShareButton>` component uses `window.location.href` to capture the current URL. Because we are running our tests at `http://localhost:4200/tests`, that's what we got. *Technically* it's not wrong, but this is certainly not what we meant. Gotta love computers!
204
204
205
-
This brings up an interesting question – why does the `currentURL()` test helper not have the same problem? In our test, we have been writing assertions like `assert.equal(currentURL(), '/about');`, and those assertions did not fail.
205
+
This brings up an interesting question – why does the `currentURL()` test helper not have the same problem? In our test, we have been writing assertions like `assert.strictEqual(currentURL(), '/about');`, and those assertions did not fail.
206
206
207
207
It turns out that this is something Ember's router handled for us. In an Ember app, the router is responsible for handling navigation and maintaining the URL. For example, when you click on a `<LinkTo>` component, it will ask the router to execute a *[route transition](../../../routing/preventing-and-retrying-transitions/)*. Normally, the router is set up to update the browser's address bar whenever it transitions into a new route. That way, your users will be able to use the browser's back button and bookmark functionality just like any other webpage.
208
208
@@ -262,16 +262,21 @@ We will take advantage of this capability in our component test:
262
262
import { setupRenderingTest } from'ember-qunit';
263
263
+importServicefrom'@ember/service';
264
264
import { render } from'@ember/test-helpers';
265
-
@@ -5,2+6,8 @@
265
+
@@ -5,2+6,13 @@
266
266
267
+
+constMOCK_URL=newURL(
268
+
+'/foo/bar?baz=true#some-section',
269
+
+window.location.origin
270
+
+);
271
+
+
267
272
+classMockRouterServiceextendsService {
268
273
+getcurrentURL() {
269
274
+return'/foo/bar?baz=true#some-section';
270
275
+ }
271
276
+}
272
277
+
273
278
module('Integration | Component | share-button', function (hooks) {
274
-
@@ -8,18+15,22 @@
279
+
@@ -8,18+20,20 @@
275
280
276
281
-test('it renders', asyncfunction (assert) {
277
282
-// Set any properties with this.set('myProperty', 'value');
@@ -300,9 +305,7 @@ We will take advantage of this capability in our component test:
0 commit comments