Test helpers


Acceptance Tests

Ember Basic Dropdown bundles some handy test helpers (clickDropdown and tapDropdown) that make it easier to simulate user interaction in acceptance tests.

To use those helpers in acceptance tests you need to register them in the /tests/helpers/start-app.js file.

For that import the registration function and invoke it immedialty.

import { run } from '@ember/runloop';
import { merge } from '@ember/polyfills';
import Application from '../../app';
import config from '../../config/environment';
import registerBasicDropdownHelpers from 'ember-basic-dropdown/test-support/helpers';

registerBasicDropdownHelpers();

export default function startApp(attrs) {
  let application;
  let attributes = merge({}, config.APP);
  attributes = merge(attributes, attrs); // use defaults, but you can override;

  run(() => {
    application = Application.create(attributes);
    application.setupForTesting();
    application.injectTestHelpers();
  });

  return application;
}

clickDropdown(cssPath, eventOptions)

Simulate a click in the trigger of the dropdown, designated with the given CSS path. If more than one element matches that dropdown, only the first one will be clicked.

clickDropdown('.notifications-menu');

tapDropdown(cssPath, eventOptions)

Simulate a tap (touchstart and touchend) in the trigger of the dropdown, designated with the given CSS path. If more than one element matches that dropdown, only the first one will be tapped.

tapDropdown('.notifications-menu');

Integration Tests

Ember Basic Dropdown also provides a few helpers for integration tests that you can import at the top of your integration tests and will ease testing.

import { clickTrigger, tapTrigger } from 'ember-basic-dropdown/test-support/helpers';

clickTrigger(scope = null, eventOptions)

Simulates a click to open or close the dropdown. As all integration test helpers is already runloop aware, so you don't need to wrap it in Ember.run.

In case there is more than one dropdown rendered at the same time you can pass a string with the scope to trigger it over the desired one.

clickTrigger();
assert.equal($('.ember-basic-dropdown-content').length, 1, 'The content is shown now');

tapTrigger(scope = null, eventOptions)

Identical to clickTrigger but simulates a tap instead.

tapTrigger();
assert.equal($('.ember-basic-dropdown-content').length, 1, 'The content is shown now');