Last Updated: February 25, 2016
·
1.168K
· fr0gs

Inject Mock Service in Unit Testing Ember (single tests)

Another quick & dirty solution that will create and inject a mock instance of an object simulating a service in a unit test.

mockExceptionService = Ember.Object.create
  removeError: (id, spec) ->
    new Ember.RSVP.Promise((resolve) ->
      resolve('I did nothing'))

test 'it changes number', ->
  expect 4

  component = @subject(
    value: 6
    exceptionService: mockExceptionService
  )

  @append()

  component.get('exceptionService').removeError(1,2).then((res) -> console.log res) // 'I did nothing'

So object is properly mocked.