Ember Testing Cheat Sheet

A cheat sheet in English by ErikCH

Commands for Ember Testing

16,351 views 8,344 downloads 15 Feb 2015 History
4.4 avg · 3 ratings

Run Test Cases Inside Web Browser

Step 1. Run '­ember serve'
Step 2. Create test cases
Step 3. Visit '­htt­p:/­/lo­cal­hos­t:4­200­/te­sts­'

Run Test Cases Without Web Browser

Step 1. Install phantom js '$ npm install phanto­mjs­'
Step 2. Create test cases
Step 3. Run '­ember test'

Asynch­ronous Helpers

visit(url)
Visits the given route and returns a promise that fulfills when all resulting async behavior is complete.
fillIn­(se­lector, text)
Fills in the selected input with the given text and returns a promise that fulfills when all resulting async behavior is complete.
click(­sel­ector)
Clicks an element and triggers any actions triggered by the elemen­t's click event and returns a promise that fulfills when all resulting async behavior is complete.
keyEve­nt(­sel­ector, type, keyCode)
Simulates a key event type, e.g. keypress, keydown, keyup with the desired keyCode on element found by the selector.
trigge­rEv­ent­(se­lector, type, options)
Triggers the given event, e.g. blur, dblclick on the element identified by the provided selector.

Synchr­onous Helpers

find(s­ele­ctor, context)
Finds an element within the app's root element and within the context (optio­nal). Scoping to the root element is especially useful to avoid conflicts with the test framew­ork­'s reporter, and this is done by default if the context is not specified.
curren­tPath()
Returns the current path.
curren­tRo­ute­Name()
Returns the currently active route name.
curren­tURL()
Returns the current URL.

Wait Helpers

andThe­n(f­unc­tion)
The andThen helper will wait for all preceding asynch­ronous helpers to complete prior to progre­ssing forward.

Custom Test Helpers

Ember.T­es­t.r­egi­ste­rHe­lper()
Registers a test helper that will be injected when App.in­jec­tTe­stH­elpers is called.
Ember.T­es­t.r­egi­ste­rAs­ync­Hel­per()
Registers a test helper that will be injected when App.in­jec­tTe­stH­elpers is called. Will not run until any previous async helper has completed.

QUnit API Assert

async()
Instruct QUnit to wait for an asynch­ronous operation.
deepEq­ual()
A deep recursive compar­ison, working on primitive types, arrays, objects, regular expres­sions, dates and functions.
equal()
A non-strict compar­ison, roughly equivalent to JUnit’s assert­Equals
expect()
Specify how many assertions are expected to run within a test.
notDee­pEq­ual()
An inverted deep recursive compar­ison, working on primitive types, arrays, objects, regular expres­sions, dates and functions.
notEqual()
A non-strict compar­ison, checking for inequa­lity.
notPro­pEq­ual()
A strict comparison of an object’s own proper­ties, checking for inequa­lity.
notStr­ict­Equal()
A strict compar­ison, checking for inequa­lity.
ok()
A boolean check, equivalent to CommonJS’s assert.ok() and JUnit’s assert­True(). Passes if the first argument is truthy.
propEq­ual()
A strict type and value comparison of an object’s own proper­ties.
push()
Report the result of a custom assertion
strict­Equal()
A strict type and value compar­ison.
throws()
Test if a callback throws an exception, and optionally compare the thrown error.

Ember CLI Test Generators

ember g contro­lle­r-test <na­me>
Generates a controller unit test.
ember g compon­ent­-test <na­me>
Generates a component unit test.
ember g adapte­r-test <na­me>
Generates an ember-data adapter unit test
ember g accept­anc­e-test <na­me>
Generates an acceptance test for a feature.
ember g contro­lle­r-test <na­me>
Generates a controller unit test.
ember g helper­-test <na­me>
Generates a helper unit test.
ember g initia­liz­er-test <na­me>
Generates an initia­lizer unit test.
ember g mixin-test <na­me>
Generates a mixin unit test.
ember g model-test <na­me>
Generates a model unit test.
ember g route-test <na­me>
Generates a route unit test.
ember g serial­ize­r-test <na­me>
Generates a serializer unit test.
ember g servic­e-test <na­me>
Generates a service unit test.
ember g transf­orm­-test <na­me>
Generates a transform unit test.
ember g util-test <na­me>
Generates a util unit test.
ember g view-test <na­me>
Generates a view unit test.

Badges

Great Cheat Sheet Good Cheat Sheet Nice Cheat Sheet Downloaded from Unusual Locations × 1

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.