Testing data in EmberJS and QUnit using fixtures

I have a simple ember application and I want to test it without making a server for API calls.

I inspected the bunch and found this piece of code that helps a lot. Testing problem. I want to use an adapter adapter (it makes sense, right?)

 @store = Lfg.__container__.lookup('store:main')

Here is my model:

Lfg.Activity = DS.Model.extend
  title: DS.attr('string')
  people: DS.attr('number')
  maxPeople: DS.attr('number')
  host: DS.attr('string')

Then inside a Em.run =>I do it

  Lfg.reset()

  container = new Ember.Container()
  # These are my models... just one for now.
  [
    'activity'
  ].forEach (x,i) ->
    container.register 'model:'+x, Lfg.get( Ember.String.classify(x) )
  # It essentially just: container.register("model:activity", Lfg.Activity)


  @store = DS.Store.create
    adapter: DS.FixtureAdapter.extend()
    container: container

But I keep getting errors using the serializer. I tried to add a serializer but didn't help. Do I need container.registerother things?

The error I am getting is TypeError: Cannot call method 'serialize' of undefinedthat coming from the mockJSON method more specifically store.serializerFor(type)returns null.

store = Lfg.__container__.lookup('store:main'), store.serializerFor(Lfg.Activity), , - ? , . , .

+3
1

- mockjax, api, qunit , Ember qunit

, json

$.mockjax({
    url:  '/colors',
    dataType: 'json',
  responseText: {
    colors:[
      {
        id: 1,
        color: "red"
      },
      {
        id: 2,
        color: "green"
      },
      {
        id: 3,
        color: "blue"
      }
     ]
  }
});

,

test("root lists 3 colors", function(){
  var store = App.__container__.lookup('store:main');
  var colors = store.find('color');
  stop();
  colors.then(function(arr){
    start();
    equal(arr.get('length'), 3, 'store returns 3 records');
  });      
});

http://emberjs.jsbin.com/wipo/3/edit

+1

All Articles