Skip to content

Instantly share code, notes, and snippets.

@everdimension
Last active January 28, 2016 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everdimension/f341f788880abdd9d0bc to your computer and use it in GitHub Desktop.
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.
// 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