Skip to content

Feature: before and after hooks #454

@artemgurzhii

Description

@artemgurzhii

We have input fields on which validation runs after focus-out, and because of that I need to write tests like this:

module('Integration | Component | login-form', function(hooks) {
  setupRenderingTest(hooks);

  test('validate inputs', async function(assert) {
    await render(hbs`<LoginForm />`);

    await page
      .email('')
      .blurEmail()
      .password('')
      .blurPassword();

    assert.ok(page.submitDisabled, 'Submit button is diabled');

    assert.equal(
      page.emailError,
      "Email can't be blank",
      'Shows error when email is blank',
    );

    assert.equal(
      page.passwordError,
      "Password can't be blank",
      'Shows error when password is blank',
    );
  });
});

Is there any way to have after option on the fillable helper, with following API:

/**
 * @param {string} selector - CSS selector of the element to look for text
 * @param {Object} options - Additional options
 * @param {string|function} options.after - event name to trigger or callback function
 */
function fillable(selector, options) {
  if (typeOf(options.after) === 'string') {
    const AVAILABLE_EVENTS = ['focut-out', 'other-event', 'one-more-event'];

    if (!AVAILABLE_EVENTS.includes(options.after)) {
      throw EmberError('Invalid after event');
    }
  }
  // ... some code
}
export default PageObject.create({
  email: fillable('[data-test-login-email] input', { after: 'focut-out' }),
  password: fillable('[data-test-login-password] input', { after: 'focut-out' }),
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions