Skip to content

Commit

Permalink
Merge pull request #9 from Ticketfly/0.2
Browse files Browse the repository at this point in the history
use an exposed initializer
  • Loading branch information
Christopher Garrett committed May 9, 2016
2 parents 61dcead + 57e7362 commit 1a6df18
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ Use the `hook` helper to define your data attribute:
Or the `hook` attribute in your component:

```js
import { HookMixin } from 'ember-hook';

export default Ember.Component.extend(HookMixin, {
export default Ember.Component.extend({
hook: 'foo'
});
```

Then in your tests:

```js
import { hook, $hook } from 'ember-hook';
import { initialize, hook, $hook } from 'ember-hook';

moduleForComponent('my component', 'Integration | Component | my component', {
integration: true,

beforeEach() {
initialize();
}
});

. . . .

Expand Down
8 changes: 5 additions & 3 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { hook, $hook } from './test-helpers/hook';
import HookMixin from './mixins/hook';
import { hook, $hook } from './test-helpers/hook';
import { initialize } from './initializers/ember-hook/initialize';

export {
hook,
HookMixin,
$hook,
HookMixin
hook,
initialize
};
13 changes: 13 additions & 0 deletions addon/initializers/ember-hook/initialize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';
import HookMixin from '../../mixins/hook';

const { Component } = Ember;

export function initialize() {
Component.reopen(HookMixin);
}

export default {
name: 'ember-hook/initialize',
initialize: initialize
};
1 change: 1 addition & 0 deletions app/initializers/ember-hook/initialize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, initialize } from 'ember-hook/initializers/ember-hook/initialize';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-hook",
"version": "0.1.1",
"version": "0.2.0",
"description": "Yerrr tests be brittle, mattie!!!",
"directories": {
"doc": "doc",
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/initializers/ember-hook/initialize-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Ember from 'ember';
import { initialize } from 'ember-hook';
import { module, test } from 'qunit';

var registry, application;

module('Unit | Initializer | ember hook/initialize', {
beforeEach: function() {
Ember.run(function() {
application = Ember.Application.create();
registry = application.registry;
application.deferReadiness();
});
}
});

test('applies the `HookMixin` to `Component`', function(assert) {
assert.expect(2);

initialize();

const { Component } = Ember;
const component = Component.create({ hook: 'foo' });

assert.deepEqual(component.get('attributeBindings'), ['ariaRole:role', '_hookName:data-test'], 'adds _hookName to the attributeBindings');
assert.equal(component.get('_hookName'), 'foo', 'adds the _hookName computed');
});

0 comments on commit 1a6df18

Please sign in to comment.