cleishm / jsmockito

Javascript mocking framework inspired by the awesome mockito

Home Page:http://jsmockito.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mocking callbacks

jackmatt2 opened this issue · comments

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?