Ember.js / Rails integration test with mount

I am trying to set up a test environment for my ember.js rails application and decided to use Konacha with mocha and chai . The biggest problem that I have at the moment is setting up fixtures for my ember models in a test environment. Can any of you explain your file structure and customize, if you have it implemented? There are several sites that explain this very briefly, but I would prefer a clearer explanation.

+6
source share
1 answer

Firstly, a few notes that can help you clarify this and get the answer you are looking for.

  • Rails elements and Ember.js elements are not related at all; Rails has little to do with it.
  • Ember.js elements can be declared in any file that your test suite requires.
  • Ember.js elements are persistent and cannot be torn down. This means that they maintain state between your tests.
  • ember-data will keep records between tests unless you explicitly destroy them.

With all that said, here is the first test_helper.coffee file from one of my projects. The file will configure Ember to test and preload your fixtures. The project used mocha and chai for testing - no other libraries are needed. I hope CoffeeScript does not cause a problem:

 #= require_tree . Efflux.setupForTesting() Efflux.injectTestHelpers() Ember.Test.adapter = Ember.Test.Adapter.extend exception: (error) -> Ember.inspect(error) throw error Efflux.Store = DS.Store.extend adapter: DS.FixtureAdapter.create(simulateRemoteResponse: false) revision: 13 Efflux.Tag.FIXTURES = [ { id: 1 name: 'alpha' group: 'symbols' }, { id: 2 name: 'beta' group: 'symbols' }, { id: 3 name: 'gamma' group: 'symbols' } ] 

Here is an example test written in BDD style and using Tag.FIXTURES:

 describe '#alphaSort', -> it 'combines the group and name into a single property', -> Ember.run -> tag = Efflux.Tag.find(3) tag.one 'didLoad', -> tag.set('group', 'greek') tag.set('name', 'alpha') expect(tag.get('alphaSort')).to.eq('greekalpha') 

It is important to note that Ember.run is used for the whole test, and the data is not available until the didLoad event didLoad . Some of the data bindings may change from the moment of writing, but this is a general idea.

+1
source

Source: https://habr.com/ru/post/956491/


All Articles