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.
Written by Esteban
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Emberjs
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#