22
33# ember-native-dom-helpers
44
5- Test helpers for integration tests that mimic the behaviour of the acceptance test
6- helpers provided by Ember.
5+ Test helpers for integration tests that mimic the behaviour of the acceptance
6+ test helpers provided by Ember.
7+
8+ Use this addon as a way to start the gradual migration towards the future
9+ "testing unification" [ RFC] [ emberjs/rfcs/pull/119 ] which proposes only native DOM.
10+
11+ See the [ Grand Testing Unification RFC] [ emberjs/rfcs/pull/119 ]
12+
13+ - [ shared-test-helpers]
14+ - [ example-migration-of-component-integration-test]
15+
16+ [ emberjs/rfcs/pull/119 ] : https://github.com/emberjs/rfcs/pull/119
17+ [ shared-test-helpers ] : https://github.com/rwjblue/rfcs/blob/42/text/0000-grand-testing-unification.md#shared-test-helpers
18+ [ example-migration-of-component-integration-test ] : https://github.com/rwjblue/rfcs/blob/42/text/0000-grand-testing-unification.md#example-migration-of-component-integration-test
19+
20+ ** Status** : (Pre) 1.0, although we have a good idea what the needs are for
21+ test helpers, we are working though a few points on what changes are needed
22+ when using only standard DOM APIs (i.e. without jQuery).
723
8- Use this addon as a way to start the gradual migration towards the future "testing unification" RFC setup. That RFC proposes only native DOM.
924
1025## Usage
1126
1227``` js
13- import { click , fillIn , find , keyEvent , triggerEvent } from ' ember-native-dom-helpers/test-support/helpers' ;
28+ import { click , fillIn , find , findAll , keyEvent , triggerEvent } from ' ember-native-dom-helpers/test-support/helpers' ;
1429
1530moduleForComponent (' my-component' , ' Integration | Component | my-component' , {
1631 integration: true
@@ -27,6 +42,7 @@ test('I can interact with my component', function(assert) {
2742 keyEvent (' .other-input' , ' keyup' , 40 ); // down arrow
2843 triggerEvent (' .some-drop-area' , ' mouseenter' );
2944 assert .ok (find (' .result-of-event-happened' ));
45+ assert .equal (findAll (' .result-list-item' ).length , 3 );
3046})
3147```
3248
@@ -64,8 +80,9 @@ The main advantages are:
6480
6581## Standard DOM elements returned using a ` find ` helper
6682
67- - The ` find ` helper uses ` document.querySelectorAll ` and will return a single ` HTMLElement `
68- or a ` NodeList ` of elements. The ` find ` helper will query the DOM within ` #ember-testing `
83+ - The ` find ` helper uses ` document.querySelector ` and will return a single ` HTMLElement ` or ` null ` .
84+ - The ` findAll ` helper uses ` document.querySelectorAll ` and returns ` NodeList ` with zero or more elements.
85+ - Both ` find ` and ` findAll ` helpers query the DOM within ` #ember-testing ` .
6986- To use a different value from your ` config/environment.js ` settings, add to ` tests/test-helper.js ` …
7087
7188``` js
@@ -80,6 +97,8 @@ settings.rootElement = rootElement || settings.rootElement;
8097
8198- ` click(selector, eventOptions) `
8299- ` fillIn(selector, text) `
83- - ` find(selector, contextHTMLElement) ` (query within test DOM, ` #ember-testing ` )
100+ - ` find(selector, contextHTMLElement) ` (query for an element in test DOM, ` #ember-testing ` )
101+ - ` findAll(selector, contextHTMLElement) ` (query for elements in test DOM, ` #ember-testing ` )
102+ - ` findWithAssert(selector, contextHTMLElement) ` (same as ` find ` , but raises Error if no result)
84103- ` keyEvent(selector, type, keyCode) ` (type being ` keydown ` , ` keyup ` or ` keypress ` )
85104- ` triggerEvent(selector, type, options) `
0 commit comments