Skip to content

Commit

Permalink
add blueprint + test helper for integration tests (#50)
Browse files Browse the repository at this point in the history
Borrowing from an approach used by ember-cli-flash, we add a helper to
duplicate the behavior of the initializer when we're running an
integration test (where initializers are not loaded). Add a blueprint
that auto-installs this helper and loads it in tests/test-helepr.js.
  • Loading branch information
bgentry authored and Turbo87 committed Jan 16, 2017
1 parent 6bf6b7c commit eb9ce87
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ Installation
ember install ember-test-selectors
```

When you install the addon, it should automatically generate a helper located at
`tests/helpers/test-selectors.js` as well as add an import to load that helper
in `tests/test-helper.js`. This sets up the component `data-test-*` auto-binding
for integration tests.

You can do this manually as well:

```
$ ember generate ember-test-selectors
```

Usage
------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions blueprints/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
env: {
node: null,
browser: true,
embertest: true,
},
};
11 changes: 11 additions & 0 deletions blueprints/files/tests/helpers/test-selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Ember from 'ember';
import bindDataTestAttributes from 'ember-test-selectors/utils/bind-data-test-attributes';

const { Component } = Ember;

Component.reopen({
init() {
this._super(...arguments);
bindDataTestAttributes(this);
}
});
17 changes: 17 additions & 0 deletions blueprints/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var EOL = require('os').EOL;

module.exports = {
description: 'Generates ember-test-selectors test helper',

afterInstall: function() {
var TEST_HELPER_PATH = 'tests/test-helper.js';
var IMPORT_STATEMENT = EOL + "import './helpers/test-selectors';";
var INSERT_AFTER = "import resolver from './helpers/resolver';";

return this.insertIntoFile(TEST_HELPER_PATH, IMPORT_STATEMENT, {
after: INSERT_AFTER
});
},

normalizeEntityName: function() {}
};

0 comments on commit eb9ce87

Please sign in to comment.