From 17af360a03b579aff1036f5c5f8160d664c30573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Buscht=C3=B6ns?= Date: Sun, 9 Feb 2020 17:04:35 +0100 Subject: [PATCH] feat: add `toString` Fixes #272. --- addon/link.ts | 13 +++++++++++++ tests/acceptance/link-test.ts | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/addon/link.ts b/addon/link.ts index 2d1b5ec3..e5be69d9 100644 --- a/addon/link.ts +++ b/addon/link.ts @@ -152,6 +152,19 @@ export default class Link { return this.url; } + /** + * Alias for `url`. + * + * Allows for more ergonomic composition as query parameters. + * + * ```hbs + * {{link "foo" query=(hash bar=(link "bar"))}} + * ``` + */ + toString() { + return this.url; + } + /** * The `RouteInfo` object for the target route. */ diff --git a/tests/acceptance/link-test.ts b/tests/acceptance/link-test.ts index bb2b1300..b48338ce 100644 --- a/tests/acceptance/link-test.ts +++ b/tests/acceptance/link-test.ts @@ -420,4 +420,21 @@ module('Acceptance | link', function(hooks) { 'exiting class is removed when transition has finished' ); }); + + test('toString()', async function(this: TestContext, assert) { + this.Router.map(function() { + this.route('foo'); + this.route('bar'); + }); + + this.owner.register( + 'template:application', + hbs`{{get (link "foo" query=(hash bar=(link "bar"))) "url"}}` + ); + + await visit('/'); + assert.equal(currentURL(), '/'); + + assert.dom().hasText('/foo?bar=%2Fbar'); + }); });