Open buschtoens opened 4 years ago
Something like this maybe?
import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { find, render, settled } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; import { setupLink, linkFor } from 'ember-link/test-support'; module('setupLink with rendering test', function(hooks) { setupRenderingTest(hooks); setupLink(hooks); test('it is a shortcut for accessing translations', async function(assert) { assert.expect(2); await render(hbs` <Link @route="foo" as |l|> <a data-test-link href={{l.url}} class={{if l.isActive "is-active"}} {{on "click" l.transitionTo}} > Link </a> </Link> `); assert.dom('[data-test-link]').hasAttribute(linkFor('foo').url); linkFor('foo').onTransitionTo(() => assert.step('transitionTo')); linkFor('foo').onReplaceWith(() => assert.step('replaceWith')); await click('[data-test-link]'); assert.verifySteps(['transitionTo']); }); });
function linkFor( route: string, ...models: RouteModel[], { ['queryParams' | 'query']: QueryParams }? ): TestLink; function linkFor({ route: string, model?: RouteModel, models?: RouteModel[], query?: QueryParams }): TestLink; interface TestLink { // all these properties can be overridden and sync to all matching `Link` instances isActive: boolean; isActiveWithoutQueryParams: boolean; isActiveWithoutModels: boolean; isEntering: boolean; isExiting: boolean; url: string; // initialized with a guid value readonly routeName: string; readonly qualifiedRouteName: string; // alias for `routeName` readonly models: RouteModel[]; readonly queryParams?: QueryParams; readonly onTransitionTo(listener: (event?: Event) => void): void; readonly onReplaceWith(listener: (event?: Event) => void): void; }
@tstormk added some amazing stuff in #305 #304 #302 #258.
Minimal docs were added in #369.
Something like this maybe?