Class @ember/test
checkWaiters public
Defined in packages/ember-testing/lib/test/waiters.ts:94
Iterates through each registered test waiter, and invokes its callback. If any waiter returns false, this method will return true indicating that the waiters have not settled yet.
This is generally used internally from the acceptance/integration test infrastructure.
currentPath Object public
Defined in packages/ember-testing/lib/helpers/current_path.ts:9
Available since v1.5.0
- returns
- Object
- The currently active path.
Returns the current path.
Example:
1 2 3 4 5 |
function validateURL() { equal(currentPath(), 'some.path.index', "correct path was transitioned into."); } click('#some-link-id').then(validateURL); |
currentRouteName Object public
Defined in packages/ember-testing/lib/helpers/current_route_name.ts:8
Available since v1.5.0
- returns
- Object
- The name of the currently active route.
Returns the currently active route name.
Example:
1 2 3 4 |
function validateRouteName() { equal(currentRouteName(), 'some.path', "correct route was transitioned into."); } visit('/some/path').then(validateRouteName) |
currentURL Object public
Defined in packages/ember-testing/lib/helpers/current_url.ts:9
Available since v1.5.0
- returns
- Object
- The currently active URL.
Returns the current URL.
Example:
1 2 3 4 5 |
function validateURL() { equal(currentURL(), '/some/path', "correct URL was transitioned into."); } click('#some-link-id').then(validateURL); |
injectTestHelpers public
Defined in packages/ember-testing/lib/ext/application.ts:103
This injects the test helpers into the helperContainer
object. If an object is provided
it will be used as the helperContainer. If helperContainer
is not set it will default
to window
. If a function of the same name has already been defined it will be cached
(so that it can be reset if the helper is removed with unregisterHelper
or
removeTestHelpers
).
Any callbacks registered with onInjectHelpers
will be called once the
helpers have been injected.
Example:
1 |
App.injectTestHelpers(); |
pauseTest Object public
Defined in packages/ember-testing/lib/helpers/pause_test.ts:22
Available since v1.9.0
- returns
- Object
- A promise that will never resolve
Pauses the current test - this is useful for debugging while testing or for test-driving. It allows you to inspect the state of your application at any point. Example (The test will pause before clicking the button):
1 2 3 |
visit('/') return pauseTest(); click('.btn'); |
You may want to turn off the timeout before pausing.
qunit (timeout available to use as of 2.4.0):
1 2 3 4 |
visit('/'); assert.timeout(0); return pauseTest(); click('.btn'); |
mocha (timeout happens automatically as of ember-mocha v0.14.0):
1 2 3 4 |
visit('/'); this.timeout(0); return pauseTest(); click('.btn'); |
registerAsyncHelper (name, helperMethod) public
Defined in packages/ember-testing/lib/test/helpers.ts:59
Available since v1.2.0
- name
- String
- The name of the helper method to add.
- helperMethod
- Function
registerAsyncHelper
is used to register an async test helper that will be injected
when App.injectTestHelpers
is called.
The helper method will always be called with the current Application as the first parameter.
For example:
1 2 3 4 5 6 |
import { registerAsyncHelper } from '@ember/test'; import { run } from '@ember/runloop'; registerAsyncHelper('boot', function(app) { run(app, app.advanceReadiness); }); |
The advantage of an async helper is that it will not run until the last async helper has completed. All async helpers after it will wait for it complete before running.
For example:
1 2 3 4 5 6 7 8 9 10 11 |
import { registerAsyncHelper } from '@ember/test'; registerAsyncHelper('deletePost', function(app, postId) { click('.delete-' + postId); }); // ... in your test visit('/post/2'); deletePost(2); visit('/post/3'); deletePost(3); |
registerHelper (name, helperMethod, options) public
Defined in packages/ember-testing/lib/test/helpers.ts:15
import { registerHelper } from '@ember/test'; |
- name
- String
- The name of the helper method to add.
- helperMethod
- Function
- options
- Object
registerHelper
is used to register a test helper that will be injected
when App.injectTestHelpers
is called.
The helper method will always be called with the current Application as the first parameter.
For example:
1 2 3 4 5 6 |
import { registerHelper } from '@ember/test'; import { run } from '@ember/runloop'; registerHelper('boot', function(app) { run(app, app.advanceReadiness); }); |
This helper can later be called without arguments because it will be
called with app
as the first parameter.
1 2 3 4 5 |
import Application from '@ember/application'; App = Application.create(); App.injectTestHelpers(); boot(); |
registerWaiter (context, callback) public
Defined in packages/ember-testing/lib/test/waiters.ts:7
Available since v1.2.0
import { registerWaiter } from '@ember/test'; |
- context
- Object
- (optional)
- callback
- Function
This allows ember-testing to play nicely with other asynchronous
events, such as an application that is waiting for a CSS3
transition or an IndexDB transaction. The waiter runs periodically
after each async helper (i.e. click
, andThen
, visit
, etc) has executed,
until the returning result is truthy. After the waiters finish, the next async helper
is executed and the process repeats.
For example:
1 2 3 4 5 |
import { registerWaiter } from '@ember/test'; registerWaiter(function() { return myPendingTransactions() === 0; }); |
The context
argument allows you to optionally specify the this
with which your callback will be invoked.
For example:
1 2 3 |
import { registerWaiter } from '@ember/test'; registerWaiter(MyDB, MyDB.hasPendingTransactions); |
removeTestHelpers public
Defined in packages/ember-testing/lib/ext/application.ts:148
This removes all helpers that have been registered, and resets and functions that were overridden by the helpers.
Example:
1 |
App.removeTestHelpers(); |
resumeTest Void public
Defined in packages/ember-testing/lib/helpers/pause_test.ts:9
- returns
- Void
Resumes a test paused by pauseTest
.
setupForTesting public
Defined in packages/ember-testing/lib/ext/application.ts:64
This hook defers the readiness of the application, so that you can start
the app when your tests are ready to run. It also sets the router's
location to 'none', so that the window's location will not be modified
(preventing both accidental leaking of state between tests and interference
with your testing framework). setupForTesting
should only be called after
setting a custom router
class (for example App.Router = Router.extend(
).
Example:
1 |
App.setupForTesting(); |
unregisterHelper (name) public
Defined in packages/ember-testing/lib/test/helpers.ts:112
import { unregisterHelper } from '@ember/test'; |
- name
- String
- The helper to remove.
Remove a previously added helper method.
Example:
1 2 3 |
import { unregisterHelper } from '@ember/test'; unregisterHelper('wait'); |
unregisterWaiter (context, callback) public
Defined in packages/ember-testing/lib/test/waiters.ts:66
Available since v1.2.0
import { unregisterWaiter } from '@ember/test'; |
- context
- Object
- (optional)
- callback
- Function
unregisterWaiter
is used to unregister a callback that was
registered with registerWaiter
.
visit (url) RSVP.Promise<undefined> public
Defined in packages/ember-testing/lib/helpers/visit.ts:6
- url
- String
- the name of the route
- returns
- RSVP.Promise<undefined>
Loads a route, sets up any controllers, and renders any templates associated with the route as though a real user had triggered the route change while using your app.
Example:
1 2 3 |
visit('posts/index').then(function() { // assert something }); |
wait (value) RSVP.Promise<any> public
Defined in packages/ember-testing/lib/helpers/wait.ts:12
Available since v1.0.0
- value
- Object
- The value to be returned.
- returns
- RSVP.Promise<any>
- Promise that resolves to the passed value.
Causes the run loop to process any pending events. This is used to ensure that any async operations from other helpers (or your assertions) have been processed.
This is most often used as the return value for the helper functions (see 'click',
'fillIn','visit',etc). However, there is a method to register a test helper which
utilizes this method without the need to actually call wait()
in your helpers.
The wait
helper is built into registerAsyncHelper
by default. You will not need
to return app.testHelpers.wait();
- the wait behavior is provided for you.
Example:
1 2 3 4 5 6 7 8 |
import { registerAsyncHelper } from '@ember/test'; registerAsyncHelper('loginUser', function(app, username, password) { visit('secured/path/here') .fillIn('#username', username) .fillIn('#password', password) .click('.submit'); }); |