Skip to content

Instantly share code, notes, and snippets.

@byelipk
Created December 9, 2014 16:58
Show Gist options
  • Save byelipk/7c557c2e70aeb031aa9f to your computer and use it in GitHub Desktop.
Save byelipk/7c557c2e70aeb031aa9f to your computer and use it in GitHub Desktop.
An example async test helper to use while integration testing addings tags with a Select2 component in an ember application.
import Ember from 'ember';
import startApp from '../helpers/start-app';
import '../helpers/complete-group-form-part-two';
var App;
module('Acceptance: AddingAutocompleteToken', {
setup: function() {
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
test('can create new token', function() {
expect(1);
visit('/autocomplete-form');
autocompleteToken('Happy');
autocompleteToken('Joy');
andThen(function() {
equal(find('.select2-search-choice').length, 2);
});
});
import Ember from 'ember';
// register custom helper
Ember.Test.registerAsyncHelper('autocompleteToken', function(app, tag) {
if (!tag) { tag = 'Test Tag'; }
triggerEvent('input.select2-input', 'keydown');
fillIn('input.select2-input', tag);
triggerEvent('input.select2-input', 'keyup');
triggerEvent('li.select2-result-selectable:first', 'mousedown');
triggerEvent('li.select2-result-selectable:first', 'mouseup');
return wait();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment