{"action":"created","issue":{"url":"https://api.github.com/repos/acdlite/flummox/issues/71","labels_url":"https://api.github.com/repos/acdlite/flummox/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/acdlite/flummox/issues/71/comments","events_url":"https://api.github.com/repos/acdlite/flummox/issues/71/events","html_url":"https://github.com/acdlite/flummox/issues/71","id":60573781,"number":71,"title":"Simulate actions when testing stores","user":{"login":"emmenko","id":1110551,"avatar_url":"https://avatars.githubusercontent.com/u/1110551?v=3","gravatar_id":"","url":"https://api.github.com/users/emmenko","html_url":"https://github.com/emmenko","followers_url":"https://api.github.com/users/emmenko/followers","following_url":"https://api.github.com/users/emmenko/following{/other_user}","gists_url":"https://api.github.com/users/emmenko/gists{/gist_id}","starred_url":"https://api.github.com/users/emmenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emmenko/subscriptions","organizations_url":"https://api.github.com/users/emmenko/orgs","repos_url":"https://api.github.com/users/emmenko/repos","events_url":"https://api.github.com/users/emmenko/events{/privacy}","received_events_url":"https://api.github.com/users/emmenko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-03-10T21:37:56Z","updated_at":"2015-03-10T22:13:28Z","closed_at":null,"body":"Hi @acdlite (again) ;)\r\n\r\nI'm sure I'm missing something but I can't get it to work. Can someone help me here?\r\n\r\nThis is my setup\r\n\r\n```javascript\r\nclass UserActions extends Actions {\r\n  getUser() {\r\n    return {\r\n      name: 'John Doe',\r\n      email: 'john@doe.com'\r\n    }\r\n  }\r\n}\r\n\r\nclass UserStore extends Store {\r\n  constructor(flux) {\r\n    super()\r\n    let userActions = flux.getActions('user')\r\n    this.register(userActions.getUser, this.handleFetchedUser)\r\n\r\n    this.state = {\r\n      user: {name: '', email: ''}\r\n    }\r\n  }\r\n\r\n  handleFetchedUser(user) {\r\n    this.setState({\r\n      user: user\r\n    })\r\n  }\r\n}\r\n\r\nclass Dispatcher extends Flux {\r\n  constructor() {\r\n    super()\r\n    this.createActions('user', UserActions)\r\n    this.createStore('user', UserStore, this)\r\n  }\r\n}\r\n\r\n\r\ndescribe('UserStore', () => {\r\n  let store, dispatcher\r\n  beforeEach(() => {\r\n    dispatcher = new Dispatcher()\r\n    store = new UserStore(dispatcher)\r\n  })\r\n\r\n  it('should update state with fetched user', () => {\r\n    spyOn(store, 'handler').and.callThrough()\r\n    spyOn(store, 'handleFetchedUser')\r\n    let actions = dispatcher.getActions('user')\r\n    FluxTestUtils.simulateAction(store, actions.getUser, 'foo')\r\n    expect(store.handler).toHaveBeenCalled()\r\n    expect(store.handleFetchedUser).toHaveBeenCalledWith('foo')\r\n  })\r\n})\r\n```\r\n\r\nI would expect `handleFetchedUser` to have been called but it's not\r\n\r\n```\r\nExpected spy handleFetchedUser to have been called.\r\n```\r\n\r\nAny idea? Thanks :)"},"comment":{"url":"https://api.github.com/repos/acdlite/flummox/issues/comments/78160058","html_url":"https://github.com/acdlite/flummox/issues/71#issuecomment-78160058","issue_url":"https://api.github.com/repos/acdlite/flummox/issues/71","id":78160058,"user":{"login":"acdlite","id":3624098,"avatar_url":"https://avatars.githubusercontent.com/u/3624098?v=3","gravatar_id":"","url":"https://api.github.com/users/acdlite","html_url":"https://github.com/acdlite","followers_url":"https://api.github.com/users/acdlite/followers","following_url":"https://api.github.com/users/acdlite/following{/other_user}","gists_url":"https://api.github.com/users/acdlite/gists{/gist_id}","starred_url":"https://api.github.com/users/acdlite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acdlite/subscriptions","organizations_url":"https://api.github.com/users/acdlite/orgs","repos_url":"https://api.github.com/users/acdlite/repos","events_url":"https://api.github.com/users/acdlite/events{/privacy}","received_events_url":"https://api.github.com/users/acdlite/received_events","type":"User","site_admin":false},"created_at":"2015-03-10T22:13:28Z","updated_at":"2015-03-10T22:13:28Z","body":"Yeah, testing in isolation with `simulateAction()` is the right approach, especially if it fetches data.\r\n\r\nHmm, not sure why it's not working after updating it like that... I'll look over it some more.\r\n\r\nYes, you'll have to pass a mock to UserStore, like so:\r\n\r\n```js\r\nlet mockDispatcher = {\r\n  getActions() {\r\n    return {\r\n      user: 'userActionId', // this can be anything, as long as it matches below\r\n    }\r\n  }\r\n};\r\n\r\nlet store = new Store(mockDispatcher);\r\n```"}}