How to test services integration?


#1

I have service, this service depends on few other services.

I wish to test how different methods play along with each other, how can I write such test? Is it documented anywhere? Are there examples available?


#2

Worked it out on my own, and seeing how this thread is already coming up in google for “integration testing services”, I’ll share my test template:

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';

var application, container, service;

module('Integration: Fake Service', {
  beforeEach: function() {
    application = startApp();
    container = application.__container__;

    // obtain initialized service from container
    service = container.lookup('service:fake');
  },

  afterEach: function() {
    Ember.run(application, 'destroy');
  }
});

// replace this with real tests
test('test service method', function(assert) {
  assert.expect(1);

  assert.ok(service.get('isFake'));
});

#3

This may also be of interest.

There is an example of injecting a service using new syntax and also testing it.