cleishm / jsmockito

Javascript mocking framework inspired by the awesome mockito
http://jsmockito.org
Other
106 stars 19 forks source link

Mocking callbacks #39

Open jackmatt2 opened 9 years ago

jackmatt2 commented 9 years ago

I am trying to use this library to test a deeply nested async call using callbacks.

var self = this;
this.store.find('employee').then(function(employee) { //promise #1
   employee.get('address').then(function(address) { //promise #2
      self.set('suburb', address.get('suburb')); //I don't care how I get here but I want to test this!
   });
});

In this case, this.store is a mock().

var mockStore = mock(DS.Store);
when(mockStore).find('employee').thenReturn(...)

What I want is to control what address is in the final callback and make sure self.suburb === address.suburb. I can't get this working because once I start mocking I have to mock our each successive return value and therefore never actually hit the code that sets the suburb.

Is this possible using jsmockito? Am I doing something wrong?