├── .editorconfig ├── .ember-cli ├── .eslintrc.js ├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── .vscode └── settings.json ├── .watchmanconfig ├── CONTRIBUTING.md ├── Changelog.md ├── LICENSE.md ├── README.md ├── addon └── .gitkeep ├── app └── .gitkeep ├── blueprints ├── .jshintrc └── ember-cli-acceptance-test-helpers │ └── index.js ├── config ├── ember-try.js └── environment.js ├── ember-cli-build.js ├── index.js ├── package.json ├── test-support └── helpers │ └── 201-created │ ├── async.js │ ├── raw │ ├── has-component.js │ ├── has-element.js │ └── has-no-element.js │ ├── register-acceptance-test-helpers.js │ ├── sync.js │ └── utils │ ├── each-view.js │ ├── find-component-elements.js │ ├── helper-context.js │ ├── lookup.js │ ├── within-element.js │ └── wrap-in-expectation.js ├── testem.js ├── tests ├── .jshintrc ├── acceptance │ ├── basic-test.js │ ├── click-component-test.js │ └── has-component-test.js ├── dummy │ ├── .jshintrc │ ├── app │ │ ├── app.js │ │ ├── components │ │ │ ├── .gitkeep │ │ │ ├── another-component.js │ │ │ ├── click-component.js │ │ │ └── simple-component.js │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── index.html │ │ ├── models │ │ │ └── .gitkeep │ │ ├── resolver.js │ │ ├── router.js │ │ ├── routes │ │ │ └── .gitkeep │ │ ├── styles │ │ │ ├── .gitkeep │ │ │ └── app.css │ │ ├── templates │ │ │ ├── .gitkeep │ │ │ ├── another.hbs │ │ │ ├── application.hbs │ │ │ ├── click-component.hbs │ │ │ ├── components │ │ │ │ ├── .gitkeep │ │ │ │ ├── click-component.hbs │ │ │ │ └── compound-component.hbs │ │ │ ├── compound-component.hbs │ │ │ ├── compound-route-outer.hbs │ │ │ ├── compound-route-outer │ │ │ │ └── compound-route-inner.hbs │ │ │ ├── contains.hbs │ │ │ ├── index.hbs │ │ │ └── two-components.hbs │ │ └── views │ │ │ └── .gitkeep │ ├── config │ │ ├── environment.js │ │ └── targets.js │ └── public │ │ ├── .gitkeep │ │ └── robots.txt ├── helpers │ ├── destroy-app.js │ ├── element-helpers.js │ ├── module-for-acceptance.js │ └── start-app.js ├── index.html ├── integration │ └── has-component-hbs-integration-test.js ├── test-helper.js └── unit │ ├── .gitkeep │ ├── basic-test.js │ ├── has-component-test.js │ ├── has-element-test.js │ └── has-no-element-test.js ├── todos.md ├── vendor └── .gitkeep └── yarn.lock /.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 | plugins: [ 8 | 'ember' 9 | ], 10 | extends: [ 11 | 'eslint:recommended', 12 | 'plugin:ember/recommended' 13 | ], 14 | env: { 15 | browser: true 16 | }, 17 | rules: {}, 18 | overrides: [ 19 | // node files 20 | { 21 | files: [ 22 | 'index.js', 23 | 'testem.js', 24 | 'ember-cli-build.js', 25 | 'config/**/*.js', 26 | 'tests/dummy/config/**/*.js' 27 | ], 28 | excludedFiles: [ 29 | 'app/**', 30 | 'addon/**', 31 | 'tests/dummy/app/**' 32 | ], 33 | parserOptions: { 34 | sourceType: 'script', 35 | ecmaVersion: 2015 36 | }, 37 | env: { 38 | browser: false, 39 | node: true 40 | }, 41 | plugins: ['node'], 42 | rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, { 43 | // add your custom rules and overrides for node files here 44 | }) 45 | }, 46 | 47 | // test files 48 | { 49 | files: ['tests/**/*.js'], 50 | excludedFiles: ['tests/dummy/**/*.js'], 51 | env: { 52 | embertest: true 53 | } 54 | } 55 | ] 56 | }; 57 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://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 | yarn-error.log 18 | testem.log 19 | .vscode/ 20 | 21 | # ember-try 22 | .node_modules.ember-try/ 23 | bower.json.ember-try 24 | package.json.ember-try 25 | -------------------------------------------------------------------------------- /.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 | "esnext": true, 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 | .eslintrc.js 11 | .gitignore 12 | .watchmanconfig 13 | .travis.yml 14 | bower.json 15 | ember-cli-build.js 16 | testem.js 17 | 18 | +# ember-try 19 | .node_modules.ember-try/ 20 | bower.json.ember-try 21 | package.json.ember-try 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | - "4" 5 | 6 | sudo: false 7 | dist: trusty 8 | 9 | addons: 10 | chrome: stable 11 | 12 | cache: 13 | yarn: true 14 | directories: 15 | - $HOME/.npm 16 | 17 | env: 18 | global: 19 | # See https://git.io/vdao3 for details. 20 | - JOBS=1 21 | matrix: 22 | # we recommend new addons test the current and previous LTS 23 | # as well as latest stable release (bonus points to beta/canary) 24 | - EMBER_TRY_SCENARIO=ember-lts-2.4 25 | - EMBER_TRY_SCENARIO=ember-lts-2.8 26 | - EMBER_TRY_SCENARIO=ember-lts-2.12 27 | - EMBER_TRY_SCENARIO=ember-lts-2.16 28 | - EMBER_TRY_SCENARIO=ember-lts-2.18 29 | - EMBER_TRY_SCENARIO=ember-release 30 | - EMBER_TRY_SCENARIO=ember-beta 31 | - EMBER_TRY_SCENARIO=ember-canary 32 | - EMBER_TRY_SCENARIO=ember-default 33 | 34 | matrix: 35 | fast_finish: true 36 | allow_failures: 37 | - env: EMBER_TRY_SCENARIO=ember-canary 38 | 39 | before_install: 40 | - npm config set spin false 41 | - npm install -g npm@4 42 | 43 | script: 44 | - npm run lint:js 45 | # Usually, it's ok to finish the test scenario without reverting 46 | # to the addon's original dependency state, skipping "cleanup". 47 | - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup 48 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | } -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | Welcome! Thanks for considering to contribute to `ember-cli-acceptance-test-helpers`. Below are the steps outlined to submit your contributions. 4 | 5 | ## Getting Started 6 | 7 | * Make sure you have a GitHub account. If you don't have one, you can sign up [here for a free account](https://github.com/signup/free). 8 | * Submit an [issue](https://github.com/201-created/ember-cli-acceptance-test-helpers/issues/new), assuming one does not already exist. 9 | * Clearly describe the bug that you are seeing or a feature you would like to add. For feature requests, feel free to include example(s) of what the api will look like after your changes. 10 | * If you want a feature but are not sure how to go about implementing it, open an issue anyways and ask for help/guidance. 11 | * [Fork the repository](https://github.com/201-created/ember-cli-acceptance-test-helpers/issues/26#fork-destination-box) on GitHub. 12 | 13 | ## Assumptions/Prerequisites 14 | 15 | This library is an Ember addon. As such, we assume the following: 16 | 17 | * You have `node` installed 18 | * If you don't have `node` installed, you can pick the way that best works for you from [this gist](https://gist.github.com/isaacs/579814). 19 | * If you don't know whether you have `node` installed or not, you can run `node -v`. If you see a version number as an output, you are good to go. Otherwise, follow one of the steps above to install `node` on your machine. 20 | * You have `ember-cli` installed globally 21 | * If you don't have `ember-cli` installed, run `npm install -g ember-cli`. Note that `node` comes with `npm` so you don't have to install `npm` separately. 22 | * If you don't know if you have `ember-cli` installed, run `ember -v`. If you see a version number as an output, you are good to go. Otherwise, follow one of the steps above to install `ember-cli` on your machine. 23 | * You have `bower` installed globally 24 | * If you don't have `bower` installed, run `npm install -g bower`. 25 | * If you don't know if you have `bower` installed, run `bower -v`. If you see a version number as an output, you are good to go. Otherwise, follow one of the steps above to install `bower` on your machine. 26 | 27 | ## Making Changes 28 | 29 | Once the above [Prerequisites][] are satisfied and you have discussed the changes you want to make in an issue, you are ready to get started coding. The steps to making changes are as follows. 30 | 31 | 1. [Clone](https://help.github.com/articles/cloning-a-repository/) the fork you created as a part of [Getting Started][]. 32 | 2. `cd` into your cloned repository on your machine. 33 | 3. Run `npm install && bower install` to install dependencies. 34 | 4. Run `npm test` to make sure the tests are passing before you start making your changes. 35 | 5. Create a topic branch from `master`. Run `git checkout -b [name of your branch]`. Please avoid working directly on the master branch. 36 | 6. Make commits of logical units. Check for unnecessary whitespace with `git diff --check` before committing. 37 | 38 | ## Submitting Changes 39 | 40 | 1. Once you have the changes working and in the state you are ready to submit, push your changes. Run `git push origin head` (this assumes you are working in a topic branch and have all the changes committed). 41 | 2. Submit a [pull request](https://help.github.com/articles/creating-a-pull-request/). 42 | 43 | There might be further changes necessary based on feedback you receive on the pull request. Feel free to ask clarifying questions or seek guidance as necessary. We hope that your contributor experience is as pleasant/smooth as can be and following these guidelines will help ensure that. Thanks for helping out! 44 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | # Ember CLI Acceptance Test Helpers Changelog 2 | 3 | ## Master 4 | 5 | # 1.0.0 6 | 7 | * changing API to support qUnit v2 8 | * Since we are adding a custom assertion to QUnit (https://qunitjs.com/cookbook/#custom-assertions), we are changing the API to `hasX` instead of `expectX` since `assert.expectComponent` sounds weird. 9 | 10 | ## 0.4.3 11 | * Support expecting zero component instances via `expectComponent('my-component', 0)` see [35](https://github.com/201-created/ember-cli-acceptance-test-helpers/pull/35) 12 | 13 | ## 0.4.2 14 | * Fix bug in `clickComponent` (see [30](https://github.com/201-created/ember-cli-acceptance-test-helpers/issues/30)) 15 | 16 | ## 0.4.1 17 | * Change `expectElement` and `expectNoElement` to accept a `message` key in the `options` hash (see [26](https://github.com/201-created/ember-cli-acceptance-test-helpers/pull/26). 18 | 19 | ## 0.4.0 20 | 21 | * Change `expectComponent` to use a container to support usage in integration tests (see [23](https://github.com/201-created/ember-cli-acceptance-test-helpers/pull/23) and [22](https://github.com/201-created/ember-cli-acceptance-test-helpers/issues/22) ) 22 | * To use `expectComponent` with component integration tests, ember-qunit version >= 0.4.7 is required 23 | * Upgrade to ember-cli 1.13.8 24 | 25 | ## 0.3.5 26 | 27 | * Remove lodash dependency 28 | 29 | ## 0.3.4 30 | 31 | * Support `expectComponent` in Ember 1.13 (@givanse) 32 | 33 | ## 0.3.3 34 | 35 | * Fix bug in `expectComponent` (@Twinkletoes) 36 | 37 | ## 0.3.2 38 | 39 | * Support Ember 1.11.0 40 | 41 | ## 0.3.1 42 | 43 | * LegacyBindAttrNode has no `get` 44 | 45 | ## 0.3.0 46 | 47 | * Link to Mocha fork (@backspace) 48 | * Add generator (@notmessenger) 49 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 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 | # Ember Test Helpers 2 | [![Build Status](https://travis-ci.org/201-created/ember-cli-acceptance-test-helpers.svg?branch=master)](https://travis-ci.org/201-created/ember-cli-acceptance-test-helpers) 3 | 4 | A set of useful helpers for ember-cli acceptance tests. Includes 5 | `hasComponent`, `hasElement`, `hasNoElement`, and `clickComponent`. 6 | 7 | ## Upgrading to 1.0 8 | 9 | In 1.0, the helper function names have changed (replacing expect with has), and the invocation changed; they are now meant to be used as QUnit assertion methods rather than as globals. 10 | 11 | To upgrade from a pre 1.0 branch, do the following: Replace the following calls: 12 | * `expectElement` -> `assert.hasElement` 13 | * `expectNoElement` -> `assert.hasNoElement` 14 | * `expectComponent` -> `assert.hasComponent` 15 | 16 | Then, open `start-app.js` and update the call to to pass in the QUnit assert object; change `registerAcceptanceTestHelpers();` to `registerAcceptanceTestHelpers(attrs.assert || window.QUnit.assert);`. You may also have to update the `module-for-acceptance.js` file to make `beforeEach` take `assert` as a first parameter, and pass `assert` into `startApp`, for example 17 | 18 | ```js 19 | beforeEach(assert) { 20 | this.application = startApp({ assert }); 21 | } 22 | ``` 23 | 24 | ## Helpers 25 | 26 | ### `hasComponent` 27 | 28 | `hasComponent(assert, componentName, count, options)` or `assert.hasComponent(componentName, count, options)` 29 | 30 | Passes when the component exists in the container and is in the DOM. 31 | 32 | `count` optional, defaults to `null`. `null` means 'at least one'. 33 | If an integer count is provided, there must be exactly that many components in the DOM. 34 | 35 | If `options.contains` is set, the expectation only passes if the 36 | component is in the DOM and contains the string from `options.contains`. 37 | 38 | `hasComponent` can also be used in component integration tests. See [has-component-hbs-integration-test.js](https://github.com/201-created/ember-cli-acceptance-test-helpers/blob/master/tests/integration/has-component-hbs-integration-test.js) for an example. 39 | Note that `ember-qunit` version 0.4.7 or greater is required to make the component integration tests work properly. 40 | 41 | ### `clickComponent` 42 | 43 | `clickComponent(assert, componentName, selector)` 44 | 45 | Clicks the CSS selector inside the component(s) of type `componentName` 46 | in the DOM. 47 | 48 | ### `hasElement` 49 | 50 | `hasElement(assert, selector, count, options)` or `assert.hasElement(selector, count, options)` 51 | 52 | Expect that `count` instances of the selector are in the DOM. 53 | 54 | `count` is optional and defaults to 1. 55 | 56 | If `options.contains` is set, the expectation will only pass if there 57 | are exactly count instances of the selector that include the string 58 | value of `options.contains`. 59 | 60 | If `options.message` is set, the message will be displayed in the test results instead of the default, `Found 0 of '.selector' but expected 1.` 61 | 62 | ### `hasNoElement` 63 | 64 | `hasNoElement(assert, selector, options)` or `assert.hasNoElement(selector, options)` 65 | 66 | A convenience for `hasElement` when the count is 0. 67 | 68 | `options` can include a `contains` and/or a `message` key. 69 | 70 | ## Mocha 71 | 72 | If you want to use this with [`ember-cli-mocha`](https://github.com/switchfly/ember-cli-mocha), try [this fork](https://github.com/backspace/ember-cli-acceptance-test-helpers/tree/use-mocha). 73 | 74 | ## Setup 75 | 76 | * Run `ember install ember-cli-acceptance-test-helpers` 77 | * Commit any file changes made if your application is under source code management 78 | 79 | After installing, Ember-CLI will run a generator. The generator makes changes to files assuming the structure of them has not changed much from the default version created during the initial Ember application creation. If too many changes have been made you will need to manually make the changes below instead: 80 | 81 | * Import the registerTestHelpers function in your `tests/helpers/start-app.js`. Add this line to to the top of `start-app.js`: 82 | * `import registerAcceptanceTestHelpers from './201-created/register-acceptance-test-helpers';` 83 | * Register the test helpers. Update `start-app.js` to call `registerAcceptanceTestHelpers`, passing in the QUnit `assert` object, before `App.injectTestHelpers`. 84 | ```js 85 | startApp(attrs) { 86 | ... 87 | registerAcceptanceTestHelpers(attrs.assert || window.QUnit.assert); 88 | ``` 89 | * Update `module-for-acceptance.js` in project to pass `assert` into `startApp` like this: 90 | ```js 91 | beforeEach(assert) { 92 | this.application = startApp({ assert }); 93 | } 94 | ``` 95 | 96 | * Update your `tests/.jshintrc` file to notify it of the new globals 97 | that these helpers have added. Add the following line to the 98 | `predef` array (after "currentRouteName"): 99 | ``` 100 | "clickComponent", 101 | ``` 102 | 103 | * You may need to restart your ember server so that it picks up the new .jshintrc file. 104 | 105 | ### Releasing Updates to NPM 106 | * Create an npm user if you don't have one using `npm adduser` 107 | * ask a team member to add your user to npm for this project 108 | * update the version in `package.json` 109 | * `npm publish` 110 | * Visit https://www.npmjs.com/package/ember-cli-acceptance-test-helpers and confirm the correct version number 111 | 112 | If you have errors running `npm adduser`, you may have previously set your npm registry to a read-only or non-standard URL. 113 | * Run this command to check `npm config get registry` 114 | * Run this command to reset:`npm config set registry https://registry.npmjs.org/` 115 | 116 | [more docs](https://docs.npmjs.com/getting-started/publishing-npm-packages) 117 | 118 | #### To do 119 | 120 | * clickLink 121 | * test/document `hasClass` option 122 | * a `within(selector/component, block&)` helper 123 | * every expectation only adds 1 expectation, so it's easy to use `expect(X)` 124 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/addon/.gitkeep -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/app/.gitkeep -------------------------------------------------------------------------------- /blueprints/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "console" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /blueprints/ember-cli-acceptance-test-helpers/index.js: -------------------------------------------------------------------------------- 1 | /* globals module */ 2 | 3 | var EOL = require('os').EOL; 4 | 5 | module.exports = { 6 | description: 'A set of useful test helpers for ember acceptance tests', 7 | 8 | afterInstall: function( options ) { 9 | // Import statement 10 | var firstFile = 'tests/helpers/start-app.js', 11 | firstText = "import registerAcceptanceTestHelpers from './201-created/register-acceptance-test-helpers';", 12 | firstLocationText = "import Ember from 'ember';" + EOL, 13 | 14 | // Execution of registration function 15 | secondFile = 'tests/helpers/start-app.js', 16 | secondText = " registerAcceptanceTestHelpers(attrs.assert || window.QUnit.assert);", 17 | secondLocationText = "App.setupForTesting();" + EOL, 18 | 19 | // .jshintrc file 20 | thirdFile = 'tests/.jshintrc', 21 | thirdText = ' "hasComponent",' + EOL + 22 | ' "clickComponent",' + EOL + 23 | ' "hasElement",' + EOL + 24 | ' "hasNoElement",', 25 | thirdLocationText = '"predef": [' + EOL; 26 | 27 | // Import statement 28 | return this.insertIntoFile( firstFile, firstText, { after: firstLocationText } ) 29 | 30 | // Execution of registration function 31 | .then( function() { 32 | return this.insertIntoFile( secondFile, secondText, { after: secondLocationText } ); 33 | }.bind(this)) 34 | 35 | // .jshintrc file 36 | .then( function() { 37 | return this.insertIntoFile( thirdFile, thirdText, { after: thirdLocationText } ); 38 | }.bind(this)); 39 | }, 40 | 41 | normalizeEntityName: function() {} 42 | }; 43 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getChannelURL = require('ember-source-channel-url'); 4 | 5 | module.exports = function() { 6 | return Promise.all([ 7 | getChannelURL('release'), 8 | getChannelURL('beta'), 9 | getChannelURL('canary'), 10 | ]).then((urls) => { 11 | return { 12 | useYarn: true, 13 | scenarios: [ 14 | { 15 | name: 'ember-lts-2.4', 16 | bower: { 17 | dependencies: { 18 | 'ember': 'components/ember#lts-2-4' 19 | }, 20 | resolutions: { 21 | 'ember': 'lts-2-4' 22 | } 23 | }, 24 | npm: { 25 | devDependencies: { 26 | 'ember-source': null 27 | } 28 | } 29 | }, 30 | { 31 | name: 'ember-lts-2.8', 32 | bower: { 33 | dependencies: { 34 | 'ember': 'components/ember#lts-2-8' 35 | }, 36 | resolutions: { 37 | 'ember': 'lts-2-8' 38 | } 39 | }, 40 | npm: { 41 | devDependencies: { 42 | 'ember-source': null 43 | } 44 | } 45 | }, 46 | { 47 | name: 'ember-lts-2.12', 48 | npm: { 49 | devDependencies: { 50 | 'ember-source': '~2.12.0' 51 | } 52 | } 53 | }, 54 | { 55 | name: 'ember-lts-2.16', 56 | npm: { 57 | devDependencies: { 58 | 'ember-source': '~2.16.0' 59 | } 60 | } 61 | }, 62 | { 63 | name: 'ember-lts-2.18', 64 | npm: { 65 | devDependencies: { 66 | 'ember-source': '~2.18.0' 67 | } 68 | } 69 | }, 70 | { 71 | name: 'ember-release', 72 | npm: { 73 | devDependencies: { 74 | 'ember-source': urls[0] 75 | } 76 | } 77 | }, 78 | { 79 | name: 'ember-beta', 80 | npm: { 81 | devDependencies: { 82 | 'ember-source': urls[1] 83 | } 84 | } 85 | }, 86 | { 87 | name: 'ember-canary', 88 | npm: { 89 | devDependencies: { 90 | 'ember-source': urls[2] 91 | } 92 | } 93 | }, 94 | { 95 | name: 'ember-default', 96 | npm: { 97 | devDependencies: {} 98 | } 99 | } 100 | ] 101 | }; 102 | }); 103 | }; 104 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function ( /* environment, appConfig */ ) { 4 | return {}; 5 | }; 6 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 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 | 'use strict'; 2 | 3 | module.exports = { 4 | name: 'ember-cli-acceptance-test-helpers' 5 | }; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-cli-acceptance-test-helpers", 3 | "main": "index.js", 4 | "version": "1.1.0", 5 | "keywords": [ 6 | "ember-addon" 7 | ], 8 | "license": "MIT", 9 | "author": "Cory Forsyth", 10 | "directories": { 11 | "doc": "doc", 12 | "test": "tests" 13 | }, 14 | "repository": "https://github.com/201-created/ember-cli-acceptance-test-helpers", 15 | "scripts": { 16 | "build": "ember build", 17 | "lint:js": "eslint ./*.js addon addon-test-support app config lib server test-support tests", 18 | "start": "ember serve", 19 | "test": "ember try:each" 20 | }, 21 | "dependencies": { 22 | "ember-cli-babel": "^6.12.0" 23 | }, 24 | "devDependencies": { 25 | "broccoli-asset-rev": "^2.7.0", 26 | "ember-cli": "~2.18.2", 27 | "ember-cli-dependency-checker": "^2.0.0", 28 | "ember-cli-eslint": "^4.2.1", 29 | "ember-cli-htmlbars": "^2.0.1", 30 | "ember-cli-htmlbars-inline-precompile": "^1.0.0", 31 | "ember-cli-inject-live-reload": "^1.4.1", 32 | "ember-cli-qunit": "^4.1.1", 33 | "ember-cli-shims": "^1.2.0", 34 | "ember-cli-sri": "^2.1.0", 35 | "ember-cli-uglify": "^2.0.0", 36 | "ember-disable-prototype-extensions": "^1.1.2", 37 | "ember-export-application-global": "^2.0.0", 38 | "ember-load-initializers": "^1.0.0", 39 | "ember-maybe-import-regenerator": "^0.1.6", 40 | "ember-resolver": "^4.0.0", 41 | "ember-source": "~2.18.0", 42 | "ember-try": "^0.2.23", 43 | "ember-source-channel-url": "^1.0.1", 44 | "eslint-plugin-ember": "^5.0.0", 45 | "eslint-plugin-node": "^5.2.1", 46 | "loader.js": "^4.2.3" 47 | }, 48 | "engines": { 49 | "node": "^4.5 || 6.* || >= 7.*" 50 | }, 51 | "ember-addon": { 52 | "configPath": "tests/dummy/config" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/async.js: -------------------------------------------------------------------------------- 1 | import {lookupComponent} from './utils/lookup'; 2 | import findComponentElements from './utils/find-component-elements'; 3 | import { assert } from '@ember/debug'; 4 | 5 | export function clickComponent(app, expectation, selector){ 6 | var container; 7 | if (app.__container__) { 8 | container = app.__container__; 9 | } else { 10 | container = app; 11 | } 12 | var Component = lookupComponent(container, expectation); 13 | 14 | if (!Component) { 15 | assert('No Component called ' + expectation + ' exists.'); 16 | return; 17 | } 18 | 19 | var elements = findComponentElements(container, Component); 20 | var context = app.$(elements); 21 | 22 | return app.testHelpers.click(selector, context); 23 | } 24 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/raw/has-component.js: -------------------------------------------------------------------------------- 1 | import {lookupComponent} from '../utils/lookup'; 2 | import eachView from '../utils/each-view'; 3 | import { isPresent } from '@ember/utils'; 4 | import $ from 'jquery'; 5 | 6 | var K = function(){}; 7 | 8 | export default function(appOrContainer, assert, expectation, count, options, customMessage){ 9 | let container; 10 | if (appOrContainer.__container__) { 11 | container = appOrContainer.__container__; 12 | } else { 13 | container = appOrContainer; 14 | } 15 | var Component = lookupComponent(container, expectation); 16 | 17 | if (!Component) { 18 | return { 19 | ok: false, 20 | message: 'No component called ' + expectation + ' was found in the container' 21 | }; 22 | } 23 | 24 | if (!options) { options = {}; } 25 | 26 | var callbackFn = options.callbackFn || K; 27 | 28 | var found = 0; 29 | 30 | var elements = []; 31 | 32 | eachView(container, function(view){ 33 | if (Component.detectInstance(view)) { 34 | found++; 35 | callbackFn(view, found); 36 | elements.push(view.element); 37 | } 38 | }); 39 | 40 | var message = count ? 41 | 'Expected to find '+count+' components of type ' + expectation + '. Found: ' + found : 42 | 'Expected to find at least one component: ' + expectation; 43 | 44 | var result = { 45 | ok: isPresent(count) ? found === count : found > 0, // if count specified then we must have exactly that many, otherwise we want at least 1 46 | message: customMessage || message 47 | }; 48 | 49 | if (result.ok && options.contains) { 50 | var text = $(elements).text(); 51 | if (text.indexOf(options.contains) === -1) { 52 | result.ok = false; 53 | result.message = 'Expected component ' + expectation + ' to contain "' + options.contains + 54 | '" but contained: "' + text + '"'; 55 | } else { 56 | result.ok = true; 57 | result.message = 'Component ' + expectation + ' contains: "' + options.contains + '"'; 58 | } 59 | } 60 | 61 | return result; 62 | } 63 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/raw/has-element.js: -------------------------------------------------------------------------------- 1 | import {getContext} from '../utils/helper-context'; 2 | 3 | function filterElements(elements, text){ 4 | return elements.filter(':contains(' + text + ')'); 5 | } 6 | 7 | function buildMessage(selector, { filteredCount, selectorCount, ok }, { contains, message, count }) { 8 | if (!message) { 9 | if (contains) { 10 | message = 'Found ' + filteredCount + ' of ' + selector + 11 | ' containing "' + contains + '"'; 12 | 13 | if (!ok) { 14 | if (selectorCount === filteredCount) { 15 | message = 'Found ' + filteredCount + ' of ' + selector + 16 | ' containing "' + contains + '" but expected ' + count; 17 | } else { 18 | message = 'Found ' + selectorCount + ' of ' + selector + 19 | ' but ' + filteredCount + '/' + count + ' containing "' + contains + '"'; 20 | } 21 | } 22 | } 23 | else { 24 | message = 'Found ' + selectorCount + ' of ' + selector; 25 | 26 | if (!ok) { 27 | message += ' but expected ' + count; 28 | } 29 | } 30 | } 31 | return message; 32 | } 33 | 34 | export default function(app, assert, selector, count, options){ 35 | if (typeof count === 'object') { 36 | options = count; 37 | } 38 | 39 | if (!options) { options = {}; } 40 | 41 | if (typeof count === 'number') { 42 | options.count = count; 43 | } 44 | 45 | if (options.count === undefined) { 46 | options.count = 1; 47 | } 48 | 49 | var elements = app.testHelpers.find(selector, getContext()); 50 | 51 | var result = {}; 52 | 53 | result.selectorCount = elements.length; 54 | 55 | if (options.contains) { 56 | let filtered = filterElements(elements, options.contains); 57 | 58 | result.ok = filtered.length === options.count; 59 | result.filteredCount = filtered.length; 60 | 61 | } else { 62 | result.ok = elements.length === options.count; 63 | } 64 | 65 | result.message = buildMessage(selector, result, options); 66 | 67 | return result; 68 | } 69 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/raw/has-no-element.js: -------------------------------------------------------------------------------- 1 | import hasElement from './has-element'; 2 | 3 | export default function(app, assert, selector, options){ 4 | if (!options) { 5 | options = {}; 6 | } 7 | 8 | return hasElement(app, assert, selector, 0, options); 9 | } 10 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/register-acceptance-test-helpers.js: -------------------------------------------------------------------------------- 1 | import { registerHelper, registerAsyncHelper } from '@ember/test'; 2 | 3 | import { wrappedExpectElement, 4 | wrappedExpectNoElement, 5 | wrappedExpectComponent } from './sync'; 6 | 7 | import withinElement from './utils/within-element'; 8 | import { assert as emberAssert } from '@ember/debug'; 9 | 10 | import { clickComponent } from './async'; 11 | 12 | export default function(assert) { 13 | emberAssert('`assert` must be passed to registerAcceptanceTestHelpers(). see README.md', !!assert); 14 | registerHelper('hasElement', wrappedExpectElement); 15 | registerHelper('hasNoElement', wrappedExpectNoElement); 16 | registerHelper('hasComponent', wrappedExpectComponent); 17 | 18 | registerHelper('withinElement', withinElement); 19 | 20 | registerAsyncHelper('clickComponent', clickComponent); 21 | 22 | assert.hasElement = function () { 23 | return hasElement(this, ...arguments); // eslint-disable-line 24 | }; 25 | assert.hasNoElement = function () { 26 | return hasNoElement(this, ...arguments); // eslint-disable-line 27 | }; 28 | assert.hasComponent = function () { 29 | return hasComponent(this, ...arguments); // eslint-disable-line 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/sync.js: -------------------------------------------------------------------------------- 1 | import wrapInExpectation from './utils/wrap-in-expectation'; 2 | 3 | import rawExpectElement from './raw/has-element'; 4 | import rawExpectNoElement from './raw/has-no-element'; 5 | import rawExpectComponent from './raw/has-component'; 6 | 7 | var wrappedExpectElement = wrapInExpectation(rawExpectElement); 8 | var wrappedExpectNoElement = wrapInExpectation(rawExpectNoElement); 9 | var wrappedExpectComponent = wrapInExpectation(rawExpectComponent); 10 | 11 | export { 12 | wrappedExpectElement, 13 | wrappedExpectNoElement, 14 | wrappedExpectComponent 15 | }; 16 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/utils/each-view.js: -------------------------------------------------------------------------------- 1 | function iterateViews(callback, callbackHistory){ 2 | return function(view) { 3 | if (!view.get) { 4 | // FIXME LegacyBindAttrNode has no `get` method 5 | return; 6 | } 7 | if (view.get('isDestroyed') || view.get('isDestroying')) { 8 | return; 9 | } 10 | 11 | /* 12 | FIXME: is it better to use `_state` to test for `isDestroy/ed/ing`? 13 | var state = view._state; 14 | if (!state) { state = view.state; } 15 | if (state !== 'inDOM') { return; } 16 | */ 17 | 18 | if (callbackHistory.indexOf(view) === -1) { 19 | callback(view); 20 | callbackHistory.push(view); 21 | } 22 | view.get('childViews').forEach(iterateViews(callback, callbackHistory)); 23 | }; 24 | } 25 | 26 | export default function(container, callback){ 27 | var allViews = container.lookup('-view-registry:main'); 28 | 29 | if ( ! allViews ) { // Ember 1.11.0 compatibility 30 | allViews = Ember.View.views; // eslint-disable-line 31 | } 32 | 33 | var views = Object.keys(allViews).map(function(viewName) { 34 | return allViews[viewName]; 35 | }); 36 | 37 | var callbackHistory = []; 38 | views.forEach(iterateViews(callback, callbackHistory)); 39 | } 40 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/utils/find-component-elements.js: -------------------------------------------------------------------------------- 1 | import eachView from './each-view'; 2 | 3 | export default function findComponentElements(container, componentKlass) { 4 | var elements = []; 5 | eachView(container, function(view){ 6 | if (componentKlass.detectInstance(view)) { 7 | elements.push(view.element); 8 | } 9 | }); 10 | 11 | return elements; 12 | } 13 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/utils/helper-context.js: -------------------------------------------------------------------------------- 1 | var context; 2 | 3 | function getContext() { 4 | return context; 5 | } 6 | 7 | function setContext(_context) { 8 | context = _context; 9 | } 10 | 11 | export { getContext, setContext }; 12 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/utils/lookup.js: -------------------------------------------------------------------------------- 1 | export function lookupRouter(container){ 2 | return container.lookup('router:main'); 3 | } 4 | 5 | export function lookupComponent(container, componentName){ 6 | if (typeof container.factoryFor === 'function') { 7 | let component = container.factoryFor('component:' + componentName); 8 | return component ? component.class : undefined; 9 | } 10 | return container.lookupFactory('component:' + componentName); 11 | } 12 | 13 | export function lookupView(container, viewName){ 14 | if (typeof container.factoryFor === 'function') { 15 | let view = container.factoryFor('view:' + viewName); 16 | return view ? view.class : undefined; 17 | } 18 | return container.lookupFactory('view:' + viewName); 19 | } 20 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/utils/within-element.js: -------------------------------------------------------------------------------- 1 | import {getContext, setContext} from './helper-context'; 2 | 3 | export default function(app, selector, callback){ 4 | var elements = app.testHelpers.find(selector); 5 | 6 | var previousContext = getContext(); 7 | setContext( elements[0] ); 8 | callback(); 9 | setContext( previousContext ); 10 | } 11 | -------------------------------------------------------------------------------- /test-support/helpers/201-created/utils/wrap-in-expectation.js: -------------------------------------------------------------------------------- 1 | export default function(helperFn){ 2 | return function(app, assert){ 3 | var result = helperFn.apply(null, arguments); 4 | 5 | assert.ok(result.ok, result.message); 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | test_page: 'tests/index.html?hidepassed', 3 | disable_watching: true, 4 | launch_in_ci: [ 5 | 'Chrome' 6 | ], 7 | launch_in_dev: [ 8 | 'Chrome' 9 | ], 10 | browser_args: { 11 | Chrome: { 12 | mode: 'ci', 13 | args: [ 14 | // --no-sandbox is needed when running Chrome inside a container 15 | process.env.TRAVIS ? '--no-sandbox' : null, 16 | 17 | '--disable-gpu', 18 | '--headless', 19 | '--remote-debugging-port=0', 20 | '--window-size=1440,900' 21 | ].filter(Boolean) 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /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": false, 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 | "esnext": true 51 | } 52 | -------------------------------------------------------------------------------- /tests/acceptance/basic-test.js: -------------------------------------------------------------------------------- 1 | import { test } from 'qunit'; 2 | import moduleForAcceptance from '../helpers/module-for-acceptance'; 3 | import hasComponentRaw from '../helpers/201-created/raw/has-component'; 4 | /* global hasComponent, hasElement, hasNoElement, withinElement */ 5 | 6 | moduleForAcceptance('Acceptance | Basic'); 7 | 8 | test('visiting /', function(assert) { 9 | assert.expect(1); 10 | visit('/'); 11 | 12 | andThen(() => { 13 | assert.equal(currentPath(), 'index'); 14 | }); 15 | }); 16 | 17 | test('visiting /, hasComponent', function(assert) { 18 | assert.expect(5); 19 | visit('/'); 20 | 21 | andThen(() => { 22 | hasComponent(assert, 'simple-component'); 23 | assert.hasComponent('simple-component') 24 | 25 | var result = hasComponentRaw(this.application, assert, 'another-component'); 26 | assert.ok(!result.ok, 'fails on invisible component'); 27 | 28 | click('.link'); 29 | 30 | andThen(() => { 31 | hasComponent(assert, 'another-component'); 32 | var result = hasComponentRaw(this.application, assert, 'simple-component'); 33 | assert.ok(!result.ok, 'fails on invisible component'); 34 | }); 35 | }); 36 | }); 37 | 38 | test('visiting /, hasElement', function(assert) { 39 | assert.expect(1); 40 | visit('/'); 41 | 42 | andThen(() => { 43 | hasElement(assert, '.some-div'); 44 | }); 45 | }); 46 | 47 | test('visiting /, hasNoElement', function(assert) { 48 | assert.expect(3); 49 | visit('/'); 50 | 51 | andThen(() => { 52 | hasNoElement(assert, '.missing-div'); 53 | hasNoElement(assert, 'h2', {contains: 'text that is not there'}); 54 | assert.hasNoElement('h2', {contains: 'text that is not there'}) 55 | }); 56 | }); 57 | 58 | test('visiting /, withinElement', function(assert) { 59 | assert.expect(4); 60 | 61 | visit('/'); 62 | 63 | andThen(() => { 64 | withinElement('.some-div', function(){ 65 | hasElement(assert, '.inner-div'); 66 | assert.hasElement('.inner-div'); 67 | hasNoElement(assert, '.outer-div'); 68 | }); 69 | 70 | hasElement(assert, 'h2'); 71 | }); 72 | }); 73 | -------------------------------------------------------------------------------- /tests/acceptance/click-component-test.js: -------------------------------------------------------------------------------- 1 | import { test } from 'qunit'; 2 | import moduleForAcceptance from '../helpers/module-for-acceptance'; 3 | /* global clickComponent, hasComponent */ 4 | 5 | moduleForAcceptance('Acceptance | click component'); 6 | 7 | test('clickComponent() API test', function(assert) { 8 | assert.expect(3); 9 | visit('/click-component'); 10 | 11 | let beforeClickText = 'CLICK IT!!!'; 12 | let afterClickText = 'Good Job'; 13 | 14 | andThen(() => { 15 | hasComponent(assert, 'click-component', 1); 16 | assert.equal(find('.txt').text().trim(), beforeClickText); 17 | clickComponent('click-component', '.btn'); 18 | 19 | andThen(() => { 20 | assert.equal(find('.txt').text().trim(), afterClickText); 21 | }); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /tests/acceptance/has-component-test.js: -------------------------------------------------------------------------------- 1 | import { test } from 'qunit'; 2 | import moduleForAcceptance from '../helpers/module-for-acceptance'; 3 | import hasComponentRaw from '../helpers/201-created/raw/has-component'; 4 | 5 | moduleForAcceptance('Acceptance | ExpectComponent'); 6 | 7 | test('hasComponent passes when component is present', function(assert) { 8 | visit('/'); 9 | 10 | andThen(() => { 11 | var result = hasComponentRaw(this.application, assert, 'simple-component'); 12 | assert.ok(result.ok, 'expected a pass'); 13 | }); 14 | }); 15 | 16 | test('hasComponent fails when component is not present', function(assert) { 17 | visit('/'); 18 | 19 | andThen(() => { 20 | let result = hasComponentRaw(this.application, assert, 'another-component'); 21 | assert.ok(!result.ok, 'expected a failure'); 22 | }); 23 | }); 24 | 25 | test('hasComponent error message says component not found when component is not present with no count', function(assert) { 26 | visit('/'); 27 | 28 | andThen(() => { 29 | var result = hasComponentRaw(this.application, assert, 'another-component'); 30 | assert.ok(result.message.indexOf('another-component') > -1, 'expected message to contain component name'); 31 | assert.ok(result.message.indexOf('Expected to find at least one component') > -1); 32 | }); 33 | }); 34 | 35 | test('hasComponent fails when component is present twice with count of 1', function(assert) { 36 | visit('/two-components'); 37 | 38 | andThen(() => { 39 | var result = hasComponentRaw(this.application, assert, 'simple-component', 1); 40 | assert.ok(!result.ok, "expected a failure"); 41 | }); 42 | }); 43 | 44 | test('hasComponent error message gives count and found when component is present twice with count of 1', function(assert) { 45 | visit('/two-components'); 46 | 47 | andThen(() => { 48 | var result = hasComponentRaw(this.application, assert, 'simple-component', 1); 49 | assert.ok(result.message.indexOf('simple-component') > -1, 'expected message to contain component name'); 50 | assert.ok(result.message.indexOf('Expected to find 1 components') > -1, 'expected message to contain "Expected to find 1 components"'); 51 | var suffix = 'Found: 2'; 52 | assert.ok(result.message.indexOf(suffix, result.message.length - suffix.length) > -1, 'expected message to end with '+suffix); 53 | }); 54 | }); 55 | 56 | test('hasComponent passes when component is present twice with count of 2', function(assert) { 57 | visit('/two-components'); 58 | 59 | andThen(() => { 60 | var result = hasComponentRaw(this.application, assert, 'simple-component', 2); 61 | assert.ok(result.ok, "expected a pass"); 62 | }); 63 | }); 64 | 65 | test('hasComponent fails when component is present twice with count of 3', function(assert) { 66 | visit('/two-components'); 67 | 68 | andThen(() => { 69 | var result = hasComponentRaw(this.application, assert, 'simple-component', 3); 70 | assert.ok(!result.ok, "expected a failure"); 71 | }); 72 | }); 73 | 74 | test('hasComponent passes when component is present twice but count unspecified', function(assert) { 75 | visit('/two-components'); 76 | 77 | andThen(() => { 78 | var result = hasComponentRaw(this.application, assert, 'simple-component'); 79 | assert.ok(result.ok, "expected a pass"); 80 | }); 81 | }); 82 | 83 | test('hasComponent passes when component is present twice and count null', function(assert) { 84 | visit('/two-components'); 85 | 86 | andThen(() => { 87 | var result = hasComponentRaw(this.application, assert, 'simple-component', null); 88 | assert.ok(result.ok, "expected a pass"); 89 | }); 90 | }); 91 | 92 | test('hasComponent passes when component is present inside a compound component', function(assert) { 93 | visit('/compound-component'); 94 | 95 | andThen(() => { 96 | var result = hasComponentRaw(this.application, assert, 'simple-component'); 97 | assert.ok(result.ok, "expected a pass"); 98 | }); 99 | }); 100 | 101 | test('hasComponent passes when component is present inside a nested route', function(assert) { 102 | visit('/compound-route-outer/compound-route-inner'); 103 | 104 | andThen(() => { 105 | var result = hasComponentRaw(this.application, assert, 'simple-component'); 106 | assert.ok(result.ok, "expected a pass"); 107 | }); 108 | }); 109 | 110 | test('hasComponent passes when component is present and text matches contains option', function(assert) { 111 | visit('/contains'); 112 | 113 | andThen(() => { 114 | var result = hasComponentRaw(this.application, assert, 'simple-component', null, {contains: 'text is present'}); 115 | assert.ok(result.ok, "expected a pass"); 116 | }); 117 | }); 118 | 119 | test('hasComponent passes when component is present and text does not match contains option', function(assert) { 120 | visit('/contains'); 121 | 122 | andThen(() => { 123 | var result = hasComponentRaw(this.application, assert, 'simple-component', null, {contains: 'penguins are present'}); 124 | assert.ok(!result.ok, "expected a failure"); 125 | }); 126 | }); 127 | 128 | test('hasComponent gives component missing error when component is not present with contains option provided', function(assert) { 129 | visit('/contains'); 130 | 131 | andThen(() => { 132 | var result = hasComponentRaw(this.application, assert, 'another-component', null, {contains: 'penguins are present'}); 133 | assert.ok(result.message.indexOf('Expected to find at least one component') > -1, 'Should get \'Expected to find component\' message'); 134 | }); 135 | }); 136 | 137 | test('hasComponent supports expecting zero component instances', function(assert) { 138 | visit('/'); 139 | 140 | andThen(() => { 141 | var result = hasComponentRaw(this.application, assert, 'another-component', 0); 142 | assert.ok(result.ok, "expected a failure"); 143 | }); 144 | }); 145 | 146 | // 'fails is the component is found but destroyed' 147 | -------------------------------------------------------------------------------- /tests/dummy/.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 | "esnext": true, 31 | "unused": true 32 | } 33 | -------------------------------------------------------------------------------- /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 | import Application from '@ember/application'; 6 | 7 | let App; 8 | 9 | Ember.MODEL_FACTORY_INJECTIONS = true; 10 | 11 | App = Application.extend({ 12 | modulePrefix: config.modulePrefix, 13 | podModulePrefix: config.podModulePrefix, 14 | Resolver 15 | }); 16 | 17 | loadInitializers(App, config.modulePrefix); 18 | 19 | export default App; 20 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/components/another-component.js: -------------------------------------------------------------------------------- 1 | import Component from '@ember/component'; 2 | 3 | export default Component.extend(); 4 | -------------------------------------------------------------------------------- /tests/dummy/app/components/click-component.js: -------------------------------------------------------------------------------- 1 | import Component from '@ember/component'; 2 | import layout from '../templates/components/click-component'; 3 | 4 | export default Component.extend({ 5 | layout, 6 | classNames: ['click-component'], 7 | text: 'click me', 8 | didClick: false, 9 | 10 | actions: { 11 | doClick() { 12 | this.toggleProperty('didClick'); 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /tests/dummy/app/components/simple-component.js: -------------------------------------------------------------------------------- 1 | import Component from '@ember/component'; 2 | 3 | export default Component.extend(); 4 | -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /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/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/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 EmberRouter from '@ember/routing/router'; 2 | import config from './config/environment'; 3 | 4 | const Router = EmberRouter.extend({ 5 | location: config.locationType, 6 | rootURL: config.rootURL 7 | }); 8 | 9 | Router.map(function() { 10 | this.route('another'); 11 | this.route('two-components'); 12 | this.route('click-component'); 13 | this.route('compound-component'); 14 | this.route('contains'); 15 | this.route('compound-route-outer', function() { 16 | this.route('compound-route-inner'); 17 | }); 18 | }); 19 | 20 | export default Router; 21 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/app/styles/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 20px; 3 | } 4 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/app/templates/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/templates/another.hbs: -------------------------------------------------------------------------------- 1 | {{another-component}} 2 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 |

hi there

2 | 3 |
4 |
5 |
6 | 7 |
8 | 9 | {{outlet}} 10 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/click-component.hbs: -------------------------------------------------------------------------------- 1 |

Click Component Route

2 | 3 | {{click-component}} -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/app/templates/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/click-component.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | {{#if didClick}} 5 | Good Job 6 | {{else}} 7 | CLICK IT!!! 8 | {{/if}} 9 |

-------------------------------------------------------------------------------- /tests/dummy/app/templates/components/compound-component.hbs: -------------------------------------------------------------------------------- 1 | {{simple-component}} -------------------------------------------------------------------------------- /tests/dummy/app/templates/compound-component.hbs: -------------------------------------------------------------------------------- 1 | {{compound-component}} 2 | 3 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/compound-route-outer.hbs: -------------------------------------------------------------------------------- 1 | {{outlet}} 2 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/compound-route-outer/compound-route-inner.hbs: -------------------------------------------------------------------------------- 1 | {{simple-component}} 2 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/contains.hbs: -------------------------------------------------------------------------------- 1 | {{#simple-component}} 2 | text is present 3 | {{/simple-component}} 4 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/index.hbs: -------------------------------------------------------------------------------- 1 | {{simple-component}} 2 | 3 | {{#link-to 'another'}} 4 | 5 | {{/link-to}} 6 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/two-components.hbs: -------------------------------------------------------------------------------- 1 | {{simple-component}} 2 | {{simple-component}} 3 | -------------------------------------------------------------------------------- /tests/dummy/app/views/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/app/views/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = function (environment) { 3 | var ENV = { 4 | modulePrefix: 'dummy', 5 | environment: environment, 6 | rootURL: '/', 7 | locationType: 'auto', 8 | EmberENV: { 9 | FEATURES: { 10 | // Here you can enable experimental features on an ember canary build 11 | // e.g. 'with-controller': true 12 | }, 13 | EXTEND_PROTOTYPES: { 14 | // Prevent Ember Data from overriding Date.parse. 15 | Date: false 16 | } 17 | }, 18 | 19 | APP: { 20 | // Here you can pass flags/options to your application instance 21 | // when it is created 22 | } 23 | }; 24 | 25 | if (environment === 'development') { 26 | // ENV.APP.LOG_RESOLVER = true; 27 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 28 | // ENV.APP.LOG_TRANSITIONS = true; 29 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 30 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 31 | } 32 | 33 | if (environment === 'test') { 34 | // Testem prefers this... 35 | ENV.locationType = 'none'; 36 | 37 | // keep test console output quieter 38 | ENV.APP.LOG_ACTIVE_GENERATION = false; 39 | ENV.APP.LOG_VIEW_LOOKUPS = false; 40 | 41 | ENV.APP.rootElement = '#ember-testing'; 42 | ENV.APP.autoboot = false; 43 | } 44 | 45 | if (environment === 'production') { 46 | // nothing 47 | } 48 | 49 | return ENV; 50 | }; 51 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const browsers = [ 3 | 'last 1 Chrome versions', 4 | 'last 1 Firefox versions', 5 | 'last 1 Safari versions' 6 | ]; 7 | 8 | const isCI = !!process.env.CI; 9 | const isProduction = process.env.EMBER_ENV === 'production'; 10 | 11 | if (isCI || isProduction) { 12 | browsers.push('ie 11'); 13 | } 14 | 15 | module.exports = { 16 | browsers 17 | }; 18 | -------------------------------------------------------------------------------- /tests/dummy/public/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/dummy/public/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/destroy-app.js: -------------------------------------------------------------------------------- 1 | import { run } from '@ember/runloop'; 2 | 3 | export default function destroyApp(application) { 4 | run(application, 'destroy'); 5 | } 6 | -------------------------------------------------------------------------------- /tests/helpers/element-helpers.js: -------------------------------------------------------------------------------- 1 | import $ from 'jquery'; 2 | 3 | export function makeElement(elementType, options){ 4 | var el = $(document.createElement(elementType)); 5 | if (options.class) { el.addClass('class', options.class); } 6 | if (options.text) { el.text(options.text); } 7 | 8 | return el.get(0); 9 | } 10 | 11 | export function makeElements(elementType, options, count){ 12 | var els = []; 13 | for (var i = 0; i < count; i++) { 14 | els.push(makeElement(elementType, options)); 15 | } 16 | 17 | return $(els); 18 | } 19 | 20 | export function makeApp(findFn){ 21 | return { 22 | testHelpers: { 23 | find: (...args) => $(findFn(...args)) 24 | }, 25 | $ 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /tests/helpers/module-for-acceptance.js: -------------------------------------------------------------------------------- 1 | import { module } from 'qunit'; 2 | import { resolve } from 'rsvp'; 3 | import startApp from '../helpers/start-app'; 4 | import destroyApp from '../helpers/destroy-app'; 5 | 6 | export default function(name, options = {}) { 7 | module(name, { 8 | beforeEach() { 9 | this.application = startApp(); 10 | 11 | if (options.beforeEach) { 12 | return options.beforeEach.apply(this, arguments); 13 | } 14 | }, 15 | 16 | afterEach() { 17 | let afterEach = options.afterEach && options.afterEach.apply(this, arguments); 18 | return resolve(afterEach).then(() => destroyApp(this.application)); 19 | } 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /tests/helpers/start-app.js: -------------------------------------------------------------------------------- 1 | import Application from '../../app'; 2 | import config from '../../config/environment'; 3 | import { merge } from '@ember/polyfills'; 4 | import { run } from '@ember/runloop'; 5 | import registerAcceptanceTestHelpers from './201-created/register-acceptance-test-helpers'; 6 | 7 | export default function startApp(attrs) { 8 | let attributes = merge({}, config.APP); 9 | attributes.autoboot = true; 10 | attributes = merge(attributes, attrs); // use defaults, but you can override; 11 | 12 | return run(() => { 13 | let application = Application.create(attributes); 14 | const assert = attributes.assert || window.QUnit.assert; 15 | registerAcceptanceTestHelpers(assert); 16 | application.setupForTesting(); 17 | application.injectTestHelpers(); 18 | return application; 19 | }); 20 | } 21 | -------------------------------------------------------------------------------- /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 | {{content-for "head-footer"}} 18 | {{content-for "test-head-footer"}} 19 | 20 | 21 | {{content-for "body"}} 22 | {{content-for "test-body"}} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {{content-for "body-footer"}} 31 | {{content-for "test-body-footer"}} 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/integration/has-component-hbs-integration-test.js: -------------------------------------------------------------------------------- 1 | import hasComponent from '../helpers/201-created/raw/has-component'; 2 | import { moduleForComponent, test } from 'ember-qunit'; 3 | import hbs from 'htmlbars-inline-precompile'; 4 | 5 | moduleForComponent('simple-component', { 6 | integration: true 7 | }); 8 | 9 | test('finds root component in hbs integration test', function(assert) { 10 | this.render(hbs`{{simple-component}}`); 11 | var result = hasComponent(this.container, assert, 'simple-component', 1); 12 | assert.ok(result.ok, "expected success"); 13 | }); 14 | 15 | test('does not find component when not present in hbs integration test', function(assert) { 16 | this.render(hbs`{{another-component}}`); 17 | var result = hasComponent(this.container, assert, 'simple-component', 1); 18 | assert.ok(!result.ok, "expected a failure"); 19 | }); 20 | 21 | test('finds inner component in hbs integration test', function(assert) { 22 | this.render(hbs`{{compound-component}}`); 23 | var result = hasComponent(this.container, assert, 'simple-component', 1); 24 | assert.ok(result.ok, "expected success"); 25 | }); 26 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from '../app'; 2 | import config from '../config/environment'; 3 | import { 4 | setApplication 5 | } from '@ember/test-helpers'; 6 | import { 7 | start 8 | } from 'ember-qunit'; 9 | 10 | setApplication(Application.create(config.APP)); 11 | 12 | start(); 13 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/basic-test.js: -------------------------------------------------------------------------------- 1 | import { module } from 'qunit'; 2 | import { test } from 'ember-qunit'; 3 | import registerAcceptanceTestHelpers from '../helpers/201-created/register-acceptance-test-helpers'; 4 | 5 | module('Unit - Basic'); 6 | 7 | test('registerAcceptanceTestHelpers exists', function(assert) { 8 | assert.ok(registerAcceptanceTestHelpers); 9 | }); 10 | -------------------------------------------------------------------------------- /tests/unit/has-component-test.js: -------------------------------------------------------------------------------- 1 | import $ from 'jquery'; 2 | import { module } from 'qunit'; 3 | import { test } from 'ember-qunit'; 4 | import hasComponent from '../helpers/201-created/raw/has-component'; 5 | 6 | module('Unit - hasComponent'); 7 | 8 | test('it exists', function(assert) { 9 | assert.ok(hasComponent, 'it exists'); 10 | }); 11 | 12 | function makeContainer(key, value){ 13 | return { 14 | factoryFor: function(_key){ 15 | if (key === _key) { return value; } 16 | } 17 | }; 18 | } 19 | 20 | function makeApp(findFn, componentName, componentKlass){ 21 | return { 22 | testHelpers: { find: findFn }, 23 | __container__: makeContainer(componentName, componentKlass), 24 | $ 25 | }; 26 | } 27 | 28 | test('fails if the component is not in the container', function(assert) { 29 | var findFn = function(){}; 30 | var DatePicker = function(){}; 31 | 32 | var app = makeApp(findFn, 'component:date-picker', DatePicker); 33 | 34 | var result = hasComponent(app, assert, 'non-existent'); 35 | assert.ok(!result.ok, 'fails'); 36 | assert.equal(result.message, 'No component called non-existent was found in the container'); 37 | }); 38 | -------------------------------------------------------------------------------- /tests/unit/has-element-test.js: -------------------------------------------------------------------------------- 1 | import { module } from 'qunit'; 2 | import { test } from 'ember-qunit'; 3 | import hasElement from '../helpers/201-created/raw/has-element'; 4 | import { 5 | makeElement, 6 | makeElements, 7 | makeApp 8 | } from '../helpers/element-helpers'; 9 | 10 | module('Unit - hasElement'); 11 | 12 | test('hasElement exists', function(assert) { 13 | assert.ok(hasElement, 'it exists'); 14 | }); 15 | 16 | test('passes when the element is found by app.testHelpers.find', function(assert) { 17 | var find = function(){ 18 | return [makeElement('div', {class:'the-div'})]; 19 | }; 20 | 21 | var app = makeApp(find); 22 | 23 | var result = hasElement(app, assert, '.the-div'); 24 | 25 | assert.ok(result.ok, 'passes'); 26 | assert.equal(result.message, 'Found 1 of .the-div'); 27 | }); 28 | 29 | test('fails when the element is not found by app.testHelpers.find', function(assert) { 30 | var find = function(){ 31 | return []; 32 | }; 33 | 34 | var app = makeApp(find); 35 | 36 | var result = hasElement(app, assert, '.the-div'); 37 | 38 | assert.ok(!result.ok, 'fails'); 39 | assert.equal(result.message, 'Found 0 of .the-div but expected 1'); 40 | }); 41 | 42 | test('calls app.testHelpers.find with the given selector', function(assert) { 43 | assert.expect(1); 44 | 45 | var find = function(selector){ 46 | assert.equal(selector, '.the-div'); 47 | return []; 48 | }; 49 | 50 | var app = makeApp(find); 51 | 52 | hasElement(app, assert, '.the-div'); 53 | }); 54 | 55 | test('can be passed a number', function(assert) { 56 | var find = function(){ 57 | return makeElements('div', {class:'the-div'}, 2); 58 | }; 59 | 60 | var app = makeApp(find); 61 | 62 | var result = hasElement(app, assert, '.the-div', 2); 63 | 64 | assert.ok(result.ok, 'passes'); 65 | assert.equal(result.message, 'Found 2 of .the-div', 'correct success message'); 66 | 67 | // default: 1 68 | result = hasElement(app, assert, '.the-div'); 69 | 70 | assert.ok(!result.ok, 'fails'); 71 | assert.equal(result.message, 'Found 2 of .the-div but expected 1', 72 | 'correct failure message'); 73 | 74 | result = hasElement(app, assert, '.the-div', 3); 75 | 76 | assert.ok(!result.ok, 'fails'); 77 | assert.equal(result.message, 'Found 2 of .the-div but expected 3', 78 | 'correct failure message'); 79 | }); 80 | 81 | test('takes option `contains`', function(assert) { 82 | var find = function(){ 83 | return makeElements('div', {class:'the-div', text: 'foo bar'}, 1); 84 | }; 85 | 86 | var app = makeApp(find); 87 | 88 | var result = hasElement(app, assert, '.the-div', {contains:'foo'}); 89 | 90 | assert.ok(result.ok, 'passes'); 91 | assert.equal(result.message, 'Found 1 of .the-div containing "foo"'); 92 | 93 | result = hasElement(app, assert, '.the-div', {contains:'not found'}); 94 | 95 | assert.ok(!result.ok, 'fails'); 96 | assert.equal(result.message, 'Found 1 of .the-div but 0/1 containing "not found"'); 97 | }); 98 | 99 | test('can be passed a number and option `contains`', function(assert) { 100 | var find = function(){ 101 | return makeElements('div', {class:'the-div', text: 'foo bar'}, 3); 102 | }; 103 | 104 | var app = makeApp(find); 105 | 106 | var result = hasElement(app, assert, '.the-div', 3, {contains:'foo'}); 107 | 108 | assert.ok(result.ok, 'passes'); 109 | assert.equal(result.message, 'Found 3 of .the-div containing "foo"'); 110 | 111 | result = hasElement(app, assert, '.the-div', 3, {contains:'not found'}); 112 | 113 | assert.ok(!result.ok, 'fails'); 114 | assert.equal(result.message, 'Found 3 of .the-div but 0/3 containing "not found"'); 115 | }); 116 | 117 | test('option `contains` filters the elements', function(assert) { 118 | var find = function(){ 119 | return [ 120 | makeElement('div', {class:'the-div'}), 121 | makeElement('div', {class:'the-div', text: 'foo bar'}) 122 | ]; 123 | }; 124 | 125 | var app = makeApp(find); 126 | 127 | var result = hasElement(app, assert, '.the-div', {contains:'foo'}); 128 | 129 | assert.ok(result.ok, 'passes'); 130 | assert.equal(result.message, 'Found 1 of .the-div containing "foo"'); 131 | 132 | result = hasElement(app, assert, '.the-div', {contains:'not found'}); 133 | 134 | assert.ok(!result.ok, 'fails'); 135 | assert.equal(result.message, 'Found 2 of .the-div but 0/1 containing "not found"'); 136 | }); 137 | 138 | test('hasElement fails with a custom message', function(assert) { 139 | let app = makeApp(() => []); 140 | let message = 'custom test label message'; 141 | let result = hasElement(app, assert, '.is-not-present', {message}); 142 | 143 | assert.ok(!result.ok, 'pre cond: fails'); 144 | assert.equal(result.message, message, 'custom message appears on hasElement fail'); 145 | }); 146 | 147 | test('hasElement passes with a custom message', function(assert) { 148 | let find = function(){ 149 | return [makeElement('div', {class:'the-div'})]; 150 | }; 151 | 152 | let app = makeApp(find); 153 | let message = 'custom test label message'; 154 | let result = hasElement(app, assert, '.is-present', {message}); 155 | 156 | assert.ok(result.ok, 'pre cond: passes'); 157 | assert.equal(result.message, message, 'custom message appears on hasElement pass'); 158 | }); 159 | 160 | test('hasElement with contains fails with a custom message', function(assert) { 161 | let app = makeApp(() => []); 162 | let message = 'custom test label message'; 163 | let result = hasElement(app, assert, '.is-not-present', {contains: 'foo', message}); 164 | 165 | assert.ok(!result.ok, 'pre cond: fails'); 166 | assert.equal(result.message, message, 'custom message appears on hasElement fail'); 167 | }); 168 | -------------------------------------------------------------------------------- /tests/unit/has-no-element-test.js: -------------------------------------------------------------------------------- 1 | import { module} from 'qunit'; 2 | import { test } from 'ember-qunit'; 3 | import hasNoElement from '../helpers/201-created/raw/has-no-element'; 4 | import { 5 | makeElement, 6 | makeElements, 7 | makeApp 8 | } from '../helpers/element-helpers'; 9 | 10 | module('Unit - hasNoElement'); 11 | 12 | test('hasNoElement exists', function(assert) { 13 | assert.ok(hasNoElement, 'it exists'); 14 | }); 15 | 16 | test('passes when the element is not found by app.testHelpers.find', function(assert) { 17 | var find = function(){ 18 | return []; 19 | }; 20 | 21 | var app = makeApp(find); 22 | 23 | var result = hasNoElement(app, assert, '.the-div'); 24 | 25 | assert.ok(result.ok, 'passes'); 26 | assert.equal(result.message, 'Found 0 of .the-div'); 27 | }); 28 | 29 | test('fails when the element is found by app.testHelpers.find', function(assert) { 30 | var find = function(){ 31 | return [makeElement('div', {class:'the-div'})]; 32 | }; 33 | 34 | var app = makeApp(find); 35 | 36 | var result = hasNoElement(app, assert, '.the-div'); 37 | 38 | assert.ok(!result.ok, 'fails'); 39 | assert.equal(result.message, 'Found 1 of .the-div but expected 0'); 40 | }); 41 | 42 | test('takes option `contains`', function(assert) { 43 | var find = function(){ 44 | return makeElements('div', {class:'the-div', text: 'foo bar'}, 1); 45 | }; 46 | 47 | var app = makeApp(find); 48 | 49 | var result = hasNoElement(app, assert, '.the-div', {contains:'boo'}); 50 | 51 | assert.ok(result.ok, 'passes'); 52 | assert.equal(result.message, 'Found 0 of .the-div containing "boo"'); 53 | 54 | result = hasNoElement(app, assert, '.the-div', {contains:'foo'}); 55 | 56 | assert.ok(!result.ok, 'fails'); 57 | assert.equal(result.message, 'Found 1 of .the-div containing "foo" but expected 0'); 58 | }); 59 | 60 | test('hasNoElement fails with a custom message', function(assert) { 61 | let find = function(){ 62 | return [makeElement('div', {class:'the-div'})]; 63 | }; 64 | let app = makeApp(find); 65 | let message = 'custom test label message'; 66 | let result = hasNoElement(app, assert, '.is-not-present', {message}); 67 | 68 | assert.ok(!result.ok, 'pre cond: fails'); 69 | assert.equal(result.message, message, 'custom message appears on hasElement fail'); 70 | }); 71 | 72 | test('hasNoElement passes with a custom message', function(assert) { 73 | let app = makeApp(() => []); 74 | let message = 'custom test label message'; 75 | let result = hasNoElement(app, assert, '.is-not-present', {message}); 76 | 77 | assert.ok(result.ok, 'pre cond: passes'); 78 | assert.equal(result.message, message, 'custom message appears on hasNoElement pass'); 79 | }); 80 | 81 | test('hasNoElement with contains passes with a custom message', function(assert) { 82 | let app = makeApp(() => []); 83 | let message = 'custom test label message'; 84 | let result = hasNoElement(app, assert, '.is-present', {contains: 'foo', message}); 85 | 86 | assert.ok(result.ok, 'pre cond: passes'); 87 | assert.equal(result.message, message, 'custom message appears on hasNoElement fail'); 88 | }); 89 | -------------------------------------------------------------------------------- /todos.md: -------------------------------------------------------------------------------- 1 | * within 2 | * clickComponent 3 | * expectInput 4 | 5 | * stubRequest/expectRequest ? 6 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/201-created/ember-cli-acceptance-test-helpers/47324f194cfd66d1015457677f78d2a585a1ed5c/vendor/.gitkeep --------------------------------------------------------------------------------