score:1

i would not recommend using async calls inside the store. it can lead to an unpredictable state of the store. and probably you may have this error: flux dispatch.dispatch(...): cannot dispatch in the middle of a dispatch.

instead, your userservice should handleaction with the user data, once the user fetched. and your store should update then the user data.

for example,

user service:

userservice.fetchuserbyid = function(userid) {
  apicall(userid).then(user => handleaction(useractions.fetch_user_by_id, user));
}

user store:

   case useractions.fetch_user_by_id:
     this.user = payload.data;
     this.emit(user_fetch_completed);
     break;

here is a good short article about fetching data with api and flux: https://medium.com/@tribou/flux-getting-data-from-an-api-b73b6478c015#.vei6eq5gt

then, you can write tests separately for your stores and services:

store test:

it('should fetch user by id', () => {
  const userstore = require('../stores/userstore');
  const mockuser = {name: 'test', id: 123};
  handleaction(useractions.fetch_user_by_id, mockuser) 
  expect(userstore.user).toequal(mockuser);
})

service test:

it('should fetch user by id', (done) => {
  const userservice = require('../service/userservice');
  // userservice.fetchuserbyid(userid);
  // here you can add spyon http service that you are using in the service
  // and mock the response from that service
  // and then validate that `handleaction` has been triggered
})

Related Query

More Query from same tag