├── .bowerrc ├── .editorconfig ├── .ember-cli ├── .eslintrc.js ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── .watchmanconfig ├── LICENSE.md ├── README.md ├── addon ├── .gitkeep ├── helpers │ └── hook.js ├── index.js ├── initializers │ └── ember-hook │ │ └── initialize.js ├── mixins │ └── hook.js ├── test-helpers │ └── hook.js └── utils │ ├── decorate-hook.js │ ├── delimit.js │ ├── delimiter.js │ ├── generate-qualifier.js │ └── return-when-testing.js ├── app ├── .gitkeep ├── helpers │ └── hook.js └── initializers │ └── ember-hook │ └── initialize.js ├── bower.json ├── config ├── ember-try.js └── environment.js ├── ember-cli-build.js ├── index.js ├── package.json ├── testem.js ├── tests ├── .eslintrc.js ├── .jshintrc ├── acceptance │ └── hook-test.js ├── blanket-options.js ├── dummy │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ ├── .gitkeep │ │ │ ├── alphabet-component.js │ │ │ └── test-component.js │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ ├── .gitkeep │ │ │ └── hash.js │ │ ├── index.html │ │ ├── models │ │ │ └── .gitkeep │ │ ├── resolver.js │ │ ├── router.js │ │ ├── routes │ │ │ └── .gitkeep │ │ ├── styles │ │ │ └── app.css │ │ └── templates │ │ │ ├── application.hbs │ │ │ └── components │ │ │ ├── .gitkeep │ │ │ ├── alphabet-component.hbs │ │ │ └── test-component.hbs │ ├── config │ │ ├── environment.js │ │ └── targets.js │ └── public │ │ ├── crossdomain.xml │ │ └── robots.txt ├── helpers │ ├── destroy-app.js │ ├── module-for-acceptance.js │ ├── resolver.js │ └── start-app.js ├── index.html ├── test-helper.js └── unit │ ├── .gitkeep │ ├── helpers │ └── hook-test.js │ └── utils │ ├── decorate-hook-test.js │ ├── delimit-test.js │ ├── generate-qualifier-test.js │ └── return-when-testing-test.js └── vendor └── .gitkeep /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "bower_components", 3 | "analytics": false 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.hbs] 17 | insert_final_newline = false 18 | 19 | [*.{diff,md}] 20 | trim_trailing_whitespace = false 21 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | ecmaVersion: 2017, 5 | sourceType: 'module' 6 | }, 7 | extends: 'eslint:recommended', 8 | env: { 9 | browser: true 10 | }, 11 | rules: { 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/* 15 | /libpeerconnection.log 16 | npm-debug.log* 17 | testem.log 18 | lcov.info 19 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "document", 4 | "window", 5 | "-Promise" 6 | ], 7 | "browser": true, 8 | "boss": true, 9 | "curly": true, 10 | "debug": false, 11 | "devel": true, 12 | "eqeqeq": true, 13 | "evil": true, 14 | "forin": false, 15 | "immed": false, 16 | "laxbreak": false, 17 | "newcap": true, 18 | "noarg": true, 19 | "noempty": false, 20 | "nonew": false, 21 | "nomen": false, 22 | "onevar": false, 23 | "plusplus": false, 24 | "regexp": false, 25 | "undef": true, 26 | "sub": true, 27 | "strict": false, 28 | "white": false, 29 | "eqnull": true, 30 | "esversion": 6, 31 | "unused": true 32 | } 33 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /bower_components 2 | /config/ember-try.js 3 | /dist 4 | /tests 5 | /tmp 6 | **/.gitkeep 7 | .bowerrc 8 | .editorconfig 9 | .ember-cli 10 | .gitignore 11 | .jshintrc 12 | .watchmanconfig 13 | .travis.yml 14 | bower.json 15 | ember-cli-build.js 16 | testem.js 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - "4" 5 | 6 | sudo: false 7 | 8 | cache: 9 | directories: 10 | - $HOME/.npm 11 | - $HOME/.cache # includes bowers cache 12 | 13 | env: 14 | - EMBER_TRY_SCENARIO=ember-lts-2.8 15 | - EMBER_TRY_SCENARIO=ember-release 16 | - EMBER_TRY_SCENARIO=ember-beta 17 | - EMBER_TRY_SCENARIO=ember-canary 18 | 19 | matrix: 20 | fast_finish: true 21 | allow_failures: 22 | - env: EMBER_TRY_SCENARIO=ember-canary 23 | 24 | before_install: 25 | - npm config set spin false 26 | - npm install -g bower 27 | - bower --version 28 | - npm install phantomjs-prebuilt 29 | - node_modules/phantomjs-prebuilt/bin/phantomjs --version 30 | 31 | install: 32 | - npm install 33 | - bower install 34 | 35 | script: 36 | # Usually, it's ok to finish the test scenario without reverting 37 | # to the addon's original dependency state, skipping "cleanup". 38 | - ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup 39 | addons: 40 | code_climate: 41 | repo_token: c77f89b85d69e49f95f19f2a06a6fdf919e40de238f9fbdad454d94bbb3388f4 42 | deploy: 43 | provider: npm 44 | email: null@midnight.agency 45 | api_key: 46 | secure: irhi64orSPHa2n9+gHnjn5Q8Y12nPiI6AdTsFQVIJXWY9qO4eLZofQQwTCwMKHZwKYEfgNJMbLDs7nlGvfUWm+UIFojY1ECcAdw5SM/9HVq6UXhdYtwW1Z/Y40hU9VVadGK3Uo4LTzIqhDE3VxkztVkPNaM/mBpq4tG0tyZQQPfoen0XqXSddv2Za4MBPuzY5Pq/43A4u1UkR+ItBchuY9v88Ktc4OLUfP0GC3fxJt1Db16figFQbahRBeJhV3RF5w3IAk72WEtFlsQE4uAaqSFLpoTUnfe0xLFexs/r/KpZzxXd10ZBUzu/WcLnJTphlshw8GTN1ywST68dCL+qEPYv7+UAx6nRkAJiSOJI3+J8G4mDLybWONCYj4wmfIAI7dWavNfJfS7QhQoooW/jw5RGE12fCcDfvnewOJhQKuhWwKUisHBPQU2VKO/7QxTTTqjnhLWrC+XsTUtTEMVOomKOdGVXK59G0aZ+CZ00oVL121zi8IPvd5iQbjNgRDoNX0dGWHkKVDlJzn+IbUE804xET0c9HdK88WEeKqk1O2UMeE0nTLw6T9kusliA094X4oS6UaDBXAVoRJvjSy8SWEpX0RjRDfkLZiqqna+0wpeycXaGP3kUtCwoVsrkwGZd80B6Xm+VsNMq2cw8ECfcBRhA9EdxbwGvWqKjCpME0wQ= 47 | on: 48 | tags: true 49 | repo: Ticketfly/ember-hook 50 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm version](https://badge.fury.io/js/ember-hook.svg)](https://badge.fury.io/js/ember-hook) 2 | [![Build Status](https://travis-ci.org/Ticketfly/ember-hook.svg?branch=master)](https://travis-ci.org/Ticketfly/ember-hook) 3 | [![Code Climate](https://codeclimate.com/github/Ticketfly/ember-hook/badges/gpa.svg)](https://codeclimate.com/github/Ticketfly/ember-hook) 4 | 5 | # ember-hook 6 | 7 | Way to go! You just completed a full and rigorous suite of acceptance tests for your Ember app! But wait, what is this? Your designers have overhauled the site, and now you need to update all your tests to reflect new class names? Well, #@!%!!! 8 | 9 | Enter `ember-hook`. Rather than coupling your tests to fickle class names, it lets you use stable data attributes. Better yet, these attributes only appear when you're running your tests, keeping your source trim and simple in production. 10 | 11 | ## Installation 12 | 13 | `ember install ember-hook` 14 | 15 | ## Usage 16 | 17 | Use the `hook` helper to define your data attribute: 18 | 19 | ```hbs 20 |
bar
21 | ``` 22 | 23 | Or the `hook` attribute in your component: 24 | 25 | ```js 26 | export default Ember.Component.extend({ 27 | hook: 'foo' 28 | }); 29 | ``` 30 | 31 | Then in your tests: 32 | 33 | ```js 34 | import { hook, $hook } from 'ember-hook'; 35 | 36 | . . . . 37 | 38 | test('my hooks work', function(assert) { 39 | assert.equal($hook('foo').text().trim(), 'bar'); // works 40 | assert.equal(find(hook('foo')).text().trim(), 'bar'); // also works 41 | }); 42 | ``` 43 | 44 | `hook` returns a string such as `[data-test="foo"]`, while `$hook` returns an actual jquery object. 45 | 46 | ### Qualifiers 47 | 48 | Class names aren't the only fickle thing about the DOM. The DOM itself is fickle. You might be tempted to scour a parent for a child element like this: 49 | 50 | ```js 51 | find(`${hook('item')}:nth(2)`); 52 | ``` 53 | 54 | But if that child element moves somewhere else in the DOM, you're in trouble. So `ember-hook` provides some tools for decoupling your hooks from the DOM structure itself. Just pass some named params into the `hook` helper: 55 | 56 | ```hbs 57 | {{#each parentArray as |childArray containerIndex|}} 58 | {{#each childArray as |item index|}} 59 |
{{item}}
60 | {{!-- or --}} 61 | {{my-component hook="item" hookQualifiers=(hash index=index containerIndex=containerIndex)}} 62 | {{/each}} 63 | {{/each}} 64 | ``` 65 | 66 | And then in your tests: 67 | 68 | ```js 69 | $hook('item', { index: 2, containerIndex: someVariable }); // grabs a very specific 'item' 70 | $hook('item', { containerIndex: 5 }); // grabs all 'items' contained by the 5th parent 71 | $hook('item'); // grabs all items 72 | ``` 73 | 74 | ### Extending 75 | Sometimes, you may want to extend `hookQualifiers` from a parent when passing it to a child. For instance, in the case above, the outer `{{#each}}` might be in one component, and the inner `{{#each}}` might be in a child. 76 | In that case, the child can extend the parent's `hookQualifiers` adding on the `index` property. This is assuming that the child was given a `hookQualifiers` property 77 | ```hbs 78 | {{#each childArray as |item index|}} 79 |
{{item}}
80 | {{!-- or --}} 81 | {{my-component hook="item" hookQualifiers=(extend hookQualifiers index=index)}} 82 | {{/each}} 83 | ``` 84 | 85 | In order for this to work, you'll need an `extend` helper, which doesn't exist natively in `Ember` but is very simple to add to your project: 86 | ```js 87 | import Ember from 'ember'; 88 | const { Helper, assign } = Ember; 89 | export function extend ([original], newProps) { 90 | return assign({}, original, newProps); 91 | } 92 | export default Helper.helper(extend); 93 | ``` 94 | 95 | ### `initialize` 96 | 97 | `ember-hook` works out-of-the-box with acceptance tests, but component integration tests present a problem: they do not run initializers. This includes the `ember-hook` initializer that allows you to use the `hook` attribute on a component. To fix this, you'll need to manually run the initializer in your component test: 98 | 99 | 100 | ```js 101 | import { initialize } from 'ember-hook'; 102 | 103 | moduleForComponent('my component', 'Integration | Component | my component', { 104 | integration: true, 105 | 106 | beforeEach() { 107 | initialize(); 108 | } 109 | }); 110 | ``` 111 | 112 | ### Changing Component Hook 113 | 114 | If there's a conflict with the property `hook` on your components, you can change the property name in your `config/environment` file: 115 | 116 | ```js 117 | // config/environment.js 118 | 119 | var ENV ={ 120 | emberHook: { 121 | hookName: 'customHookName' 122 | } 123 | } 124 | ``` 125 | 126 | ### Changing Component Hook Qualifier 127 | 128 | If there's a conflict with the property `hookQualifiers` on your components, you can change the property name in your `config/environment` file: 129 | 130 | ```js 131 | // config/environment.js 132 | 133 | var ENV ={ 134 | emberHook: { 135 | hookQualifierName: 'customHookQualifierName' 136 | } 137 | } 138 | ``` 139 | 140 | ### Changing the Delimiter 141 | 142 | `ember-hook` delimits qualifiers by appending the string '&^%^&' to each. If this happens to conflict with something your code, you can change it in the config as well: 143 | 144 | ```js 145 | // config/environment.js 146 | 147 | var ENV ={ 148 | emberHook: { 149 | delimiter: '¯\_(0)_/¯' 150 | } 151 | } 152 | ``` 153 | 154 | ### Enabling ember-hook outside of the test environment 155 | 156 | `ember-hook` by default is enabled when the environment is `test` or `development`. If you need to force ember-hook to be enabled in other environments, or always on, you can use `enabled`. 157 | 158 | ```js 159 | // config/environment.js 160 | 161 | var ENV ={ 162 | emberHook: { 163 | enabled: true 164 | } 165 | } 166 | ``` 167 | 168 | ```js 169 | // config/environment.js 170 | module.exports = function(environment) { 171 | var ENV ={ 172 | emberHook: { 173 | // only enable in test or production builds 174 | enabled: environment === 'production' 175 | } 176 | } 177 | 178 | // ... 179 | } 180 | ``` 181 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/addon/.gitkeep -------------------------------------------------------------------------------- /addon/helpers/hook.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import config from 'ember-get-config'; 3 | import decorateHook from 'ember-hook/utils/decorate-hook'; 4 | import delimit from 'ember-hook/utils/delimit'; 5 | import returnWhenTesting from 'ember-hook/utils/return-when-testing'; 6 | 7 | const { Helper } = Ember; 8 | 9 | /** 10 | * Test if an object is empty `Ember.isEmpty` surprisingly doesn't do that 11 | * @see {@link https://github.com/emberjs/ember.js/issues/5543} 12 | * @see {@link https://github.com/emberjs/ember.js/blob/v2.10.0/packages/ember-metal/lib/is_empty.js} 13 | * 14 | * @param {Object} obj - the object to test 15 | * @returns {Boolean} true if there are no keys on the object 16 | */ 17 | function isEmpty (obj = {}) { 18 | if (obj === null) { 19 | return true; 20 | } 21 | 22 | return Object.keys(obj).length === 0; 23 | } 24 | 25 | export function hook([hook, qualifierObj = {}], attributes = {}) { 26 | if (typeof qualifierObj !== 'object') { 27 | throw new Error(`The qualifier object passed to the "hook" helper must be an object not a ${typeof qualifierObj}`); 28 | } 29 | 30 | if (!isEmpty(qualifierObj) && !isEmpty(attributes)) { 31 | throw new Error('Either provide your own qualifier object, or add attributes to the "hook" helper, not both.'); 32 | } 33 | 34 | let qualifiers = isEmpty(qualifierObj) ? attributes : qualifierObj; 35 | return returnWhenTesting(config, decorateHook(delimit(hook), qualifiers)); 36 | } 37 | 38 | export default Helper.helper(hook); 39 | -------------------------------------------------------------------------------- /addon/index.js: -------------------------------------------------------------------------------- 1 | import HookMixin from './mixins/hook'; 2 | import { hook, $hook } from './test-helpers/hook'; 3 | import { initialize } from './initializers/ember-hook/initialize'; 4 | 5 | export { 6 | HookMixin, 7 | $hook, 8 | hook, 9 | initialize 10 | }; 11 | -------------------------------------------------------------------------------- /addon/initializers/ember-hook/initialize.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import HookMixin from '../../mixins/hook'; 3 | 4 | const { Component } = Ember; 5 | 6 | export function initialize() { 7 | Component.reopen(HookMixin); 8 | } 9 | 10 | export default { 11 | name: 'ember-hook/initialize', 12 | initialize: initialize 13 | }; 14 | -------------------------------------------------------------------------------- /addon/mixins/hook.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import config from 'ember-get-config'; 3 | import decorateHook from 'ember-hook/utils/decorate-hook'; 4 | import delimit from 'ember-hook/utils/delimit'; 5 | import returnWhenTesting from 'ember-hook/utils/return-when-testing'; 6 | 7 | const { 8 | Mixin, 9 | computed, 10 | get, 11 | set 12 | } = Ember; 13 | 14 | const hookName = get(config, 'emberHook.hookName') || 'hook'; 15 | const hookQualifierName = get(config, 'emberHook.hookQualifierName') || 'hookQualifiers'; 16 | 17 | export default Mixin.create({ 18 | init() { 19 | this._super(...arguments); 20 | 21 | if (this.tagName || this.elementId) { 22 | let newAttributeBindings = []; 23 | let bindings = get(this, 'attributeBindings'); 24 | 25 | if (Array.isArray(bindings)) { 26 | newAttributeBindings = newAttributeBindings.concat(bindings); 27 | } 28 | 29 | newAttributeBindings.push('_hookName:data-test'); 30 | set(this, 'attributeBindings', newAttributeBindings); 31 | } 32 | }, 33 | 34 | _hookName: computed(hookName, hookQualifierName, { 35 | get() { 36 | const hook = get(this, hookName); 37 | const qualifiers = get(this, hookQualifierName); 38 | 39 | if (hook) { 40 | return returnWhenTesting(config, decorateHook(delimit(hook), qualifiers)); 41 | } 42 | } 43 | }).readOnly() 44 | }); 45 | -------------------------------------------------------------------------------- /addon/test-helpers/hook.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import decorateHook from 'ember-hook/utils/decorate-hook'; 3 | import delimit from 'ember-hook/utils/delimit'; 4 | 5 | export function hook(name, qualifiers = {}) { 6 | const hookQuery = `[data-test^="${delimit(name)}"]`; 7 | 8 | return decorateHook(hookQuery, qualifiers, (text) => `[data-test*="${text}"]`); 9 | } 10 | 11 | export function $hook(...args) { 12 | return Ember.$(hook(...args)); 13 | } 14 | -------------------------------------------------------------------------------- /addon/utils/decorate-hook.js: -------------------------------------------------------------------------------- 1 | import generateQualifier from './generate-qualifier'; 2 | 3 | export default function decorateHook(hook, qualifiers = {}, wrapper = (text) => text) { 4 | return Object.keys(qualifiers).sort().reduce((decoratedHook, key) => { 5 | return `${decoratedHook}${wrapper(generateQualifier(qualifiers, key))}`; 6 | }, hook); 7 | } 8 | -------------------------------------------------------------------------------- /addon/utils/delimit.js: -------------------------------------------------------------------------------- 1 | import delimiter from 'ember-hook/utils/delimiter'; 2 | 3 | export default function delimit(base) { 4 | return `${base}${delimiter}`; 5 | } 6 | -------------------------------------------------------------------------------- /addon/utils/delimiter.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import config from 'ember-get-config'; 3 | 4 | const { get } = Ember; 5 | 6 | let delimiter = get(config, 'emberHook.delimiter'); 7 | 8 | if (typeof delimiter === 'undefined') { 9 | delimiter = '&^%^&'; 10 | } 11 | 12 | export default delimiter; 13 | -------------------------------------------------------------------------------- /addon/utils/generate-qualifier.js: -------------------------------------------------------------------------------- 1 | import delimit from 'ember-hook/utils/delimit'; 2 | 3 | export default function generateQualifier(object, key) { 4 | return delimit(`${key}=${object[key]}`); 5 | } 6 | -------------------------------------------------------------------------------- /addon/utils/return-when-testing.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | const { get } = Ember; 4 | 5 | export default function returnWhenTesting(config, value) { 6 | const enabled = get(config, 'emberHook.enabled'); 7 | 8 | if (typeof enabled === 'boolean' ? enabled : config.environment === 'test' || config.environment === 'development') { 9 | return value; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/app/.gitkeep -------------------------------------------------------------------------------- /app/helpers/hook.js: -------------------------------------------------------------------------------- 1 | export { default, hook } from 'ember-hook/helpers/hook'; 2 | -------------------------------------------------------------------------------- /app/initializers/ember-hook/initialize.js: -------------------------------------------------------------------------------- 1 | export { default, initialize } from 'ember-hook/initializers/ember-hook/initialize'; 2 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-hook" 3 | } 4 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | module.exports = { 3 | scenarios: [ 4 | { 5 | name: 'ember-lts-2.4', 6 | bower: { 7 | dependencies: { 8 | 'ember': 'components/ember#lts-2-4' 9 | }, 10 | resolutions: { 11 | 'ember': 'lts-2-4' 12 | } 13 | }, 14 | npm: { 15 | devDependencies: { 16 | 'ember-source': null 17 | } 18 | } 19 | }, 20 | { 21 | name: 'ember-lts-2.8', 22 | bower: { 23 | dependencies: { 24 | 'ember': 'components/ember#lts-2-8' 25 | }, 26 | resolutions: { 27 | 'ember': 'lts-2-8' 28 | } 29 | }, 30 | npm: { 31 | devDependencies: { 32 | 'ember-source': null 33 | } 34 | } 35 | }, 36 | { 37 | name: 'ember-release', 38 | bower: { 39 | dependencies: { 40 | 'ember': 'components/ember#release' 41 | }, 42 | resolutions: { 43 | 'ember': 'release' 44 | } 45 | }, 46 | npm: { 47 | devDependencies: { 48 | 'ember-source': null 49 | } 50 | } 51 | }, 52 | { 53 | name: 'ember-beta', 54 | bower: { 55 | dependencies: { 56 | 'ember': 'components/ember#beta' 57 | }, 58 | resolutions: { 59 | 'ember': 'beta' 60 | } 61 | }, 62 | npm: { 63 | devDependencies: { 64 | 'ember-source': null 65 | } 66 | } 67 | }, 68 | { 69 | name: 'ember-canary', 70 | bower: { 71 | dependencies: { 72 | 'ember': 'components/ember#canary' 73 | }, 74 | resolutions: { 75 | 'ember': 'canary' 76 | } 77 | }, 78 | npm: { 79 | devDependencies: { 80 | 'ember-source': null 81 | } 82 | } 83 | }, 84 | { 85 | name: 'ember-default', 86 | npm: { 87 | devDependencies: {} 88 | } 89 | } 90 | ] 91 | }; 92 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | module.exports = function(/* environment, appConfig */) { 5 | return { }; 6 | }; 7 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 3 | 4 | module.exports = function(defaults) { 5 | var app = new EmberAddon(defaults, { 6 | // Add options here 7 | }); 8 | 9 | /* 10 | This build file specifies the options for the dummy test app of this 11 | addon, located in `/tests/dummy` 12 | This build file does *not* influence how the addon or the app using it 13 | behave. You most likely want to be modifying `./index.js` or app's build file 14 | */ 15 | 16 | return app.toTree(); 17 | }; 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 'use strict'; 3 | 4 | module.exports = { 5 | name: 'ember-hook' 6 | }; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-hook", 3 | "version": "1.4.2", 4 | "description": "Yerrr tests be brittle, mattie!!!", 5 | "keywords": [ 6 | "ember-addon" 7 | ], 8 | "license": "MIT", 9 | "author": "", 10 | "directories": { 11 | "doc": "doc", 12 | "test": "tests" 13 | }, 14 | "scripts": { 15 | "build": "ember build", 16 | "start": "ember server", 17 | "test": "ember try:each" 18 | }, 19 | "repository": "https://github.com/Ticketfly/ember-hook", 20 | "dependencies": { 21 | "ember-cli-babel": "^6.0.0", 22 | "ember-get-config": "^0.2.0" 23 | }, 24 | "devDependencies": { 25 | "broccoli-asset-rev": "^2.4.5", 26 | "ember-ajax": "^3.0.0", 27 | "ember-cli": "2.13.2", 28 | "ember-cli-app-version": "^2.0.0", 29 | "ember-cli-dependency-checker": "^1.3.0", 30 | "ember-cli-htmlbars": "^1.1.1", 31 | "ember-cli-htmlbars-inline-precompile": "^0.4.0", 32 | "ember-cli-inject-live-reload": "^1.4.1", 33 | "ember-cli-jshint": "^2.0.1", 34 | "ember-cli-qunit": "^4.0.0", 35 | "ember-cli-shims": "^1.1.0", 36 | "ember-cli-eslint": "^3.0.0", 37 | "ember-cli-release": "^0.2.9", 38 | "ember-cli-sri": "^2.1.0", 39 | "ember-cli-test-loader": "^1.1.0", 40 | "ember-cli-uglify": "^1.2.0", 41 | "ember-data": "^2.10.0", 42 | "ember-disable-prototype-extensions": "^1.1.0", 43 | "ember-export-application-global": "^2.0.0", 44 | "ember-load-initializers": "^1.0.0", 45 | "ember-resolver": "^4.0.0", 46 | "ember-source": "~2.13.0", 47 | "loader.js": "^4.2.3" 48 | }, 49 | "engines": { 50 | "node": ">= 6" 51 | }, 52 | "ember-addon": { 53 | "configPath": "tests/dummy/config" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | module.exports = { 3 | "test_page": "tests/index.html?hidepassed", 4 | "disable_watching": true, 5 | "launch_in_ci": [ 6 | "PhantomJS" 7 | ], 8 | "launch_in_dev": [ 9 | "PhantomJS", 10 | "Chrome" 11 | ] 12 | }; 13 | -------------------------------------------------------------------------------- /tests/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 3 | module.exports = { 4 | env: { 5 | embertest: true 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /tests/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "document", 4 | "window", 5 | "location", 6 | "setTimeout", 7 | "$", 8 | "-Promise", 9 | "define", 10 | "console", 11 | "visit", 12 | "exists", 13 | "fillIn", 14 | "click", 15 | "keyEvent", 16 | "triggerEvent", 17 | "find", 18 | "findWithAssert", 19 | "wait", 20 | "DS", 21 | "andThen", 22 | "currentURL", 23 | "currentPath", 24 | "currentRouteName" 25 | ], 26 | "node": false, 27 | "browser": false, 28 | "boss": true, 29 | "curly": true, 30 | "debug": false, 31 | "devel": false, 32 | "eqeqeq": true, 33 | "evil": true, 34 | "forin": false, 35 | "immed": false, 36 | "laxbreak": false, 37 | "newcap": true, 38 | "noarg": true, 39 | "noempty": false, 40 | "nonew": false, 41 | "nomen": false, 42 | "onevar": false, 43 | "plusplus": false, 44 | "regexp": false, 45 | "undef": true, 46 | "sub": true, 47 | "strict": false, 48 | "white": false, 49 | "eqnull": true, 50 | "esversion": 6, 51 | "unused": true 52 | } 53 | -------------------------------------------------------------------------------- /tests/acceptance/hook-test.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import { module, test } from 'qunit'; 3 | import startApp from '../../tests/helpers/start-app'; 4 | import { hook, $hook } from 'ember-hook'; 5 | 6 | module('Acceptance | hook', { 7 | beforeEach: function() { 8 | this.application = startApp(); 9 | }, 10 | 11 | afterEach: function() { 12 | Ember.run(this.application, 'destroy'); 13 | } 14 | }); 15 | 16 | test('visiting /', function(assert) { 17 | assert.expect(9); 18 | const { $ } = Ember; 19 | 20 | visit('/'); 21 | 22 | andThen(() => { 23 | assert.equal($(hook('title')).text().trim(), 'Ember Hook'); 24 | assert.equal($hook('title').text().trim(), 'Ember Hook'); 25 | 26 | assert.equal($hook('component-hook').length, 3); 27 | assert.equal($hook('component-hook', { index: 2 }).text().trim(), 'Component 3'); 28 | 29 | assert.equal($hook('letter').length, 5, 'gathers all instances when no qualifiers are provided'); 30 | assert.equal($hook('letter', { groupIndex: 0 }).length, 2, 'gathers all instances that satisfy the qualifier'); 31 | assert.equal($hook('letter', { index: 1, groupIndex: 1 }).text().trim(), 'D', 'gathers the instance that satisfies multiple qualifiers'); 32 | 33 | assert.equal($hook('half').text().trim(), 'half', 'grabs half'); 34 | assert.equal($hook('half_and_half').text().trim(), 'half and half', 'grabs half_and_half'); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/blanket-options.js: -------------------------------------------------------------------------------- 1 | /* globals blanket, module */ 2 | 3 | var options = { 4 | modulePrefix: 'ember-hook', 5 | filter: '//.*ember-hook/.*/', 6 | antifilter: '//.*(tests|template).*/', 7 | loaderExclusions: [], 8 | enableCoverage: true, 9 | cliOptions: { 10 | reporters: ['lcov'], 11 | autostart: true, 12 | lcovOptions: { 13 | outputFile: 'lcov.info', 14 | //provide a function to rename es6 modules to a file path 15 | renamer: function(moduleName){ 16 | var root = /^ember-hook/; 17 | return moduleName.replace(root, 'addon') + '.js'; 18 | } 19 | } 20 | } 21 | }; 22 | if (typeof exports === 'undefined') { 23 | blanket.options(options); 24 | } else { 25 | module.exports = options; 26 | } 27 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import Resolver from './resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from './config/environment'; 5 | 6 | let App; 7 | 8 | Ember.MODEL_FACTORY_INJECTIONS = true; 9 | 10 | App = Ember.Application.extend({ 11 | modulePrefix: config.modulePrefix, 12 | podModulePrefix: config.podModulePrefix, 13 | Resolver 14 | }); 15 | 16 | loadInitializers(App, config.modulePrefix); 17 | 18 | export default App; 19 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/components/alphabet-component.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | const { 4 | Component 5 | } = Ember; 6 | 7 | export default Component.extend({ 8 | alphabet: [['A', 'B'], ['C', 'D', 'E']] 9 | }); 10 | -------------------------------------------------------------------------------- /tests/dummy/app/components/test-component.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import { HookMixin } from 'ember-hook'; 3 | 4 | const { Component } = Ember; 5 | 6 | export default Component.extend(HookMixin); 7 | -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/hash.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | export function hash(params, object) { 4 | return object; 5 | } 6 | 7 | export default Ember.Helper.helper(hash); 8 | -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember-resolver'; 2 | 3 | export default Resolver; 4 | -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import config from './config/environment'; 3 | 4 | const Router = Ember.Router.extend({ 5 | location: config.locationType, 6 | rootURL: config.rootURL 7 | }); 8 | 9 | Router.map(function() { 10 | }); 11 | 12 | export default Router; 13 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/tests/dummy/app/styles/app.css -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 |

Ember Hook

2 | 3 | {{test-component hook="component-hook" text="Component"}} 4 | {{test-component hook="component-hook" hookQualifiers=(hash index=1) text="Component 2"}} 5 | {{test-component hook="component-hook" hookQualifiers=(hash index=2) text="Component 3"}} 6 | 7 | {{alphabet-component}} 8 | 9 |

half

10 |

half and half

11 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/tests/dummy/app/templates/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/alphabet-component.hbs: -------------------------------------------------------------------------------- 1 | {{#each alphabet as |group groupIndex|}} 2 | {{#each group as |letter index|}} 3 |
{{letter}}
4 | {{/each}} 5 | {{/each}} 6 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/test-component.hbs: -------------------------------------------------------------------------------- 1 | {{text}} 2 | -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 3 | module.exports = function(environment) { 4 | var ENV = { 5 | modulePrefix: 'dummy', 6 | environment: environment, 7 | rootURL: '/', 8 | locationType: 'auto', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. 'with-controller': true 13 | }, 14 | EXTEND_PROTOTYPES: { 15 | // Prevent Ember Data from overriding Date.parse. 16 | Date: false 17 | } 18 | }, 19 | 20 | APP: { 21 | // Here you can pass flags/options to your application instance 22 | // when it is created 23 | } 24 | }; 25 | 26 | if (environment === 'development') { 27 | // ENV.APP.LOG_RESOLVER = true; 28 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 29 | // ENV.APP.LOG_TRANSITIONS = true; 30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 31 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 32 | } 33 | 34 | if (environment === 'test') { 35 | // Testem prefers this... 36 | ENV.locationType = 'none'; 37 | 38 | // keep test console output quieter 39 | ENV.APP.LOG_ACTIVE_GENERATION = false; 40 | ENV.APP.LOG_VIEW_LOOKUPS = false; 41 | 42 | ENV.APP.rootElement = '#ember-testing'; 43 | } 44 | 45 | if (environment === 'production') { 46 | 47 | } 48 | 49 | return ENV; 50 | }; 51 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 3 | module.exports = { 4 | browsers: [ 5 | 'ie 9', 6 | 'last 1 Chrome versions', 7 | 'last 1 Firefox versions', 8 | 'last 1 Safari versions' 9 | ] 10 | }; 11 | -------------------------------------------------------------------------------- /tests/dummy/public/crossdomain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/destroy-app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | 3 | export default function destroyApp(application) { 4 | Ember.run(application, 'destroy'); 5 | } 6 | -------------------------------------------------------------------------------- /tests/helpers/module-for-acceptance.js: -------------------------------------------------------------------------------- 1 | import { module } from 'qunit'; 2 | import Ember from 'ember'; 3 | import startApp from '../helpers/start-app'; 4 | import destroyApp from '../helpers/destroy-app'; 5 | 6 | const { RSVP: { Promise } } = Ember; 7 | 8 | export default function(name, options = {}) { 9 | module(name, { 10 | beforeEach() { 11 | this.application = startApp(); 12 | 13 | if (options.beforeEach) { 14 | return options.beforeEach.apply(this, arguments); 15 | } 16 | }, 17 | 18 | afterEach() { 19 | let afterEach = options.afterEach && options.afterEach.apply(this, arguments); 20 | return Promise.resolve(afterEach).then(() => destroyApp(this.application)); 21 | } 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /tests/helpers/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from '../../resolver'; 2 | import config from '../../config/environment'; 3 | 4 | const resolver = Resolver.create(); 5 | 6 | resolver.namespace = { 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix 9 | }; 10 | 11 | export default resolver; 12 | -------------------------------------------------------------------------------- /tests/helpers/start-app.js: -------------------------------------------------------------------------------- 1 | import Ember from 'ember'; 2 | import Application from '../../app'; 3 | import config from '../../config/environment'; 4 | 5 | export default function startApp(attrs) { 6 | let attributes = Ember.merge({}, config.APP); 7 | attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; 8 | 9 | return Ember.run(() => { 10 | let application = Application.create(attributes); 11 | application.setupForTesting(); 12 | application.injectTestHelpers(); 13 | return application; 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | {{content-for "test-head"}} 12 | 13 | 14 | 15 | 16 | 17 | 18 | {{content-for "head-footer"}} 19 | {{content-for "test-head-footer"}} 20 | 21 | 22 | {{content-for "body"}} 23 | {{content-for "test-body"}} 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | {{content-for "body-footer"}} 34 | {{content-for "test-body-footer"}} 35 | 36 | 37 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import resolver from './helpers/resolver'; 2 | import { 3 | setResolver 4 | } from 'ember-qunit'; 5 | import { start } from 'ember-cli-qunit'; 6 | 7 | setResolver(resolver); 8 | start(); 9 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/helpers/hook-test.js: -------------------------------------------------------------------------------- 1 | import { hook } from 'dummy/helpers/hook'; 2 | import { module, test } from 'qunit'; 3 | 4 | module('Unit | Helper | hook'); 5 | 6 | test('it handles simple case', function(assert) { 7 | let result = hook(['myHook']); 8 | assert.equal(result, 'myHook&^%^&', 'constructs the hook properly'); 9 | }); 10 | 11 | test('it handles qualifier attribute case', function(assert) { 12 | let result = hook(['myHook'], {foo: 'bar', fizz: 'bang'}); 13 | assert.equal(result, 'myHook&^%^&fizz=bang&^%^&foo=bar&^%^&', 'constructs the hook properly'); 14 | }); 15 | 16 | test('it handles qualifier object case', function(assert) { 17 | let result = hook(['myHook', {foo: 'bar'}]); 18 | assert.equal(result, 'myHook&^%^&foo=bar&^%^&', 'constructs the hook properly'); 19 | }); 20 | 21 | test('it errors when including both a qualifier object and qualifier attributes', function(assert) { 22 | assert.throws( 23 | function () { 24 | hook(['myHook', {foo: 'bar'}], {fizz: 'bang'}); 25 | }, 26 | /Either provide your own qualifier object, or add attributes to the "hook" helper, not both/, 27 | 'raised error includes proper message' 28 | ); 29 | }); 30 | 31 | test('it errors when passing in a non-object as a qualifer object', function(assert) { 32 | assert.throws( 33 | function () { 34 | hook(['myHook', 'foo-bar'], {fizz: 'bang'}); 35 | }, 36 | /The qualifier object passed to the "hook" helper must be an object not a string/, 37 | 'raised error includes proper message' 38 | ); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/unit/utils/decorate-hook-test.js: -------------------------------------------------------------------------------- 1 | import decorateHook from 'ember-hook/utils/decorate-hook'; 2 | import delimiter from 'ember-hook/utils/delimiter'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('Unit | Utility | decorate hook'); 6 | 7 | test('it decorates the hook with qualifiers', function(assert) { 8 | assert.expect(1); 9 | 10 | const result = decorateHook('foo', { bar: 'baz', aff: 'arf', zap: 'zork' }); 11 | 12 | assert.equal(result, `fooaff=arf${delimiter}bar=baz${delimiter}zap=zork${delimiter}`, 'decorates with sorted key value pairs'); 13 | }); 14 | 15 | test('it wraps the content if a callback is provided', function(assert) { 16 | assert.expect(1); 17 | 18 | const result = decorateHook('foo', { bar: 'baz', aff: 'arf', zap: 'zork' }, (text) => `<${text}>`); 19 | 20 | assert.equal(result, `foo`, 'wrapped correctly'); 21 | }); 22 | -------------------------------------------------------------------------------- /tests/unit/utils/delimit-test.js: -------------------------------------------------------------------------------- 1 | import delimit from 'ember-hook/utils/delimit'; 2 | import delimiter from 'ember-hook/utils/delimiter'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('Unit | Utility | delimit'); 6 | 7 | test('it appends the delimiter to a string', function(assert) { 8 | assert.expect(1); 9 | 10 | const result = delimit('foo'); 11 | 12 | assert.equal(result, `foo${delimiter}`, 'generates the correct string'); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/unit/utils/generate-qualifier-test.js: -------------------------------------------------------------------------------- 1 | import generateQualifier from 'ember-hook/utils/generate-qualifier'; 2 | import delimiter from 'ember-hook/utils/delimiter'; 3 | import { module, test } from 'qunit'; 4 | 5 | module('Unit | Utility | generate qualifier'); 6 | 7 | test('it returns the correct qualifier', function(assert) { 8 | assert.expect(1); 9 | 10 | const object = { foo: 'bar', baz: 'boozle' }; 11 | const result = generateQualifier(object, 'foo'); 12 | 13 | assert.equal(result, `foo=bar${delimiter}`, 'generates the correct qualifier'); 14 | }); 15 | -------------------------------------------------------------------------------- /tests/unit/utils/return-when-testing-test.js: -------------------------------------------------------------------------------- 1 | import returnWhenTesting from 'ember-hook/utils/return-when-testing'; 2 | import { module, test } from 'qunit'; 3 | 4 | module('Unit | Utility | test environment'); 5 | 6 | test('it returns the second argument if the first has a development environment', function(assert) { 7 | const result = returnWhenTesting({ environment: 'development' }, 'foo'); 8 | assert.equal(result, 'foo'); 9 | }); 10 | 11 | test('it returns the second argument if the first has a test environment', function(assert) { 12 | const result = returnWhenTesting({ environment: 'test' }, 'foo'); 13 | assert.equal(result, 'foo'); 14 | }); 15 | 16 | test('it returns nothing if the first argument does not contain test environment', function(assert) { 17 | const result = returnWhenTesting({ environment: 'production' }, 'foo'); 18 | assert.equal(result, undefined); 19 | }); 20 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ticketfly/ember-hook/c379dd48a33c274a8126bf596bddbbe5cdf36774/vendor/.gitkeep --------------------------------------------------------------------------------