Ember CLI: How to do Asynchronous Model Unit Testing with RESTAdapter -



Ember CLI: How to do Asynchronous Model Unit Testing with RESTAdapter -

i want test models, , integration rest api, using ember testing framework ships ember cli, requests, using restadapter settings not beingness made in tests, within model tests. stands, phone call save() on model cause tests next not execute:

here test made check interaction server (rest api):

test "store can used send info server", -> store = @store() ember.run -> cpanel = store.createrecord "item" cpanel.save().then((response) => equal(response.status, 200) )

this blocks tests next one; furthermore, no requests made server, when monitoring network tab in chrome dev tools:

a friend advised me utilize qunit async helper, when using that, find this.store() undefined (perhaps ember qunit adapter decided leave out back upwards async testing helpers?):

asynctest "async creates business relationship on server", -> expect(2) store = @store() ember.run => business relationship = store.createrecord("account", { sitename: "sample account" url: "http://url.com" }) account.save().then((response) => equal(response.status, 200) ok business relationship start() )

how can write async test individual models, , test integration rest api using ember qunit framework in ember cli without having write integration tests?

i'm not sure status coming from, promise of save returns record, not response server.

in order utilize start, must utilize stop first.

stop(); someasynccall(function(){ start(); });

and store injected routes , controllers, , isn't in scope of tests. you'll need utilize container store.

store = app.__container__.lookup('store:main');

it'd this:

test("save record", function(){ var record, store = app.__container__.lookup('store:main'); stop(); em.run(function(){ record = store.createrecord('color', {color:'green'}); record.save().then(function(){ start(); equal(record.get('id'), 1); }); }); });

example: http://emberjs.jsbin.com/wipo/49/edit

unit-testing asynchronous ember.js ember-data ember-cli

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -