Test data generation for Ember.js (e.g. factory_girl or driver)

I am writing integration and integration tests with the Ember.js application and I cannot connect to the server when the application is under testing. This means that I need to use the DS.FixtureAdapter to back up my data store.

But I'm not personally a fan of fixtures in large applications, because it is so difficult to find one set of fixtures that work with each test case. I prefer tools like factory_girl and the driver, which allow me to generate test data that is isolated from all other tests:

FactoryGirl.define do factory :user do name 'John Doe' date_of_birth { 21.years.ago } end end # In specific test cases: user = FactoryGirl.build(:user) young_user = FactoryGirl.create(:user, date_of_birth: 17.years.ago) 

Of course, factory_girl and the driver can also automatically create related models.

Is there an easy way to do this in Ember.js right now? Are there methods, conventions, or libraries that can make this easier? Googling has no real options yet.

+4
source share
3 answers

I recently created a project called Ember Data Factory Guy to help create hardware data for ember projects that use ember data. It works with a REST or ActiveModel adapter and has test assistants to make it pretty simple.

Look at here:

https://github.com/danielspaniel/ember-data-factory-guy

It supports attribTo, hasMany (even polymorphic) associations .. sequences embedded belongs to .. and a few more things.

+5
source

In the past, I used the rake task to create a group of objects with FactoryGirl, and then uploaded it through a serializer to the fixtures.json file.

Pros:

  • It holds DRY stuff when you have complex serialization logic or computed attributes.
  • You gain more confidence in your tests.

Minuses:

  • This is a bit hacky.
  • Usability - this is because you have to remember to restore the instrument file (slow, tedious).
  • It is difficult to generate different sets of fixtures for different test cases, so you basically stick to a global set of fixtures.

There is currently no code, but this is not a very complicated setup. I am on the fence about whether the pros outperform the cons.

By the way, the generation of fixtures "on the fly" for Konachi would be too slow to be used, I found (see # 60 ).
+2
source

I think you can generate data in the client and mock request. I suggest you use jasmine or mocha with factory_girl js .

To generate data

 FactoryGirl.define('user', function() { this.id = 1 }) FactoryGirl.create('user') 

more details here: https://github.com/Coffa/factory_girl

emberjs

can you check here what is the setup for using the Ember Test Assistants?

+1
source

All Articles