ember.jsqunitember-testing

Ember Js testing a service with promises


How to test a method inside a service that returns a store in Ember Unit Test using qunit

export default Ember.Service.extend({

store: Ember.inject.service(),

    setSomeProps() {
        this.get('store').find('somemodel', id)
          .then((someData) => {
            this.set('someProp', someDate.get('name'));
          });
    }

});

The setSomeProps is a method inside my service, I am fairly new to ember and cannot get my head around ember unit test. Whats the best way to write a unit test for this function


Solution

  • You can mock the store service in your unit test of store-caller-service. You should use wait function for asynchronous test behaviour which is described here.

    Take a look at this twiddle example