Last active
January 28, 2016 15:49
-
-
Save everdimension/f341f788880abdd9d0bc to your computer and use it in GitHub Desktop.
Test code demonstrating that two stores created using redux-api fail to listen to the same action.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DrawerApi.js | |
// ** code from demo ommitted ** | |
// | |
// AnotherApi.js | |
import Api from '../src/redux-apis'; | |
export default class AnotherApi extends Api { | |
constructor(state = { drawerIsOpened: false }) { | |
super(state); | |
// setting handler for the action with the same name 'OPEN' | |
this.setHandler('OPEN', (state, action) => { | |
console.log('AnotherApi listened to OPEN'); | |
return { | |
...state, | |
drawerIsOpened: true | |
}; | |
}); | |
} | |
knowsDrawerIsOpened() { | |
return this.getState().drawerIsOpened; | |
} | |
open() { | |
this.dispatch(this.createAction('OPEN')()); | |
} | |
} | |
// TwoStoresApi.spec.js | |
import Api, { link } from '../src/redux-apis'; | |
import DrawerApi from './DrawerApi'; | |
import AnotherApi from './AnotherApi'; | |
import { expect } from 'chai'; | |
describe('Two stores', () => { | |
it('AnotherApi reacts to actions it was called with', () => { | |
let another = new AnotherApi(); | |
expect(another.knowsDrawerIsOpened()).to.equal(false); | |
another.open(); | |
expect(another.knowsDrawerIsOpened()).to.equal(true); // this passes | |
}); | |
it('should listen and react to the same action if they want to', () => { | |
let drawer = new DrawerApi(); | |
let another = new AnotherApi(); | |
expect(drawer.isOpen()).to.equal(false); | |
expect(another.knowsDrawerIsOpened()).to.equal(false); | |
drawer.open(); | |
expect(drawer.isOpen()).to.equal(true); | |
expect(another.knowsDrawerIsOpened()).to.equal(true); // this fails! | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment