Simulate actions when testing stores
- Vorherrschende Sprache
- JavaScript
- Sterne
- 1.7k
- Forks
- 109
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Hi @acdlite (again) ;)
I'm sure I'm missing something but I can't get it to work. Can someone help me here?
This is my setup
``` javascript
class UserActions extends Actions {
getUser() {
return {
name: 'John Doe',
email: 'john@doe.com'
}
}
}
class UserStore extends Store {
constructor(flux) {
super()
let userActions = flux.getActions('user')
this.register(userActions.getUser, this.handleFetchedUser)
this.state = {
user: {name: '', email: ''}
}
}
handleFetchedUser(user) {
this.setState({
user: user
})
}
}
class Dispatcher extends Flux {
constructor() {
super()
this.createActions('user', UserActions)
this.createStore('user', UserStore, this)
}
}
describe('UserStore', () => {
let store, dispatcher
beforeEach(() => {
dispatcher = new Dispatcher()
store = new UserStore(dispatcher)
})
it('should update state with fetched user', () => {
spyOn(store, 'handler').and.callThrough()
spyOn(store, 'handleFetchedUser')
let actions = dispatcher.getActions('user')
FluxTestUtils.simulateAction(store, actions.getUser, 'foo')
expect(store.handler).toHaveBeenCalled()
expect(store.handleFetchedUser).toHaveBeenCalledWith('foo')
})
})
```
I would expect `handleFetchedUser` to have been called but it's not
```
Expected spy handleFetchedUser to have been called.
```
Any idea? Thanks :)
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.