Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Helpers #257

Open
buschtoens opened this issue Jan 29, 2020 · 1 comment
Open

Test Helpers #257

buschtoens opened this issue Jan 29, 2020 · 1 comment

Comments

@buschtoens
Copy link
Owner

buschtoens commented Jan 29, 2020

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;
}
@buschtoens
Copy link
Owner Author

@tstormk added some amazing stuff in #305 #304 #302 #258.

Minimal docs were added in #369.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant