Added errors store with tests
This commit is contained in:
parent
3353eb913a
commit
2a8cc80a86
|
@ -6,6 +6,7 @@
|
|||
.*/node_modules/react-side-effect/.*
|
||||
.*/node_modules/fbjs/.*
|
||||
.*/node_modules/config-chain/.*
|
||||
*.test.js
|
||||
|
||||
[libs]
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
// @flow
|
||||
import { observable, action } from 'mobx';
|
||||
|
||||
class UiStore {
|
||||
@observable errors = observable.array([]);
|
||||
|
||||
/* Actions */
|
||||
|
||||
@action add = (errorMessage: string): void => {
|
||||
this.errors.push(errorMessage);
|
||||
};
|
||||
|
||||
@action remove = (index: number): void => {
|
||||
this.errors.splice(index, 1);
|
||||
};
|
||||
}
|
||||
|
||||
export default UiStore;
|
|
@ -0,0 +1,27 @@
|
|||
/* eslint-disable */
|
||||
import ErrorsStore from './ErrorsStore';
|
||||
|
||||
// Actions
|
||||
describe('ErrorsStore', () => {
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
store = new ErrorsStore();
|
||||
});
|
||||
|
||||
test('#add should add errors', () => {
|
||||
expect(store.errors.length).toBe(0);
|
||||
store.add('first error');
|
||||
store.add('second error');
|
||||
expect(store.errors.length).toBe(2);
|
||||
});
|
||||
|
||||
test('#remove should remove errors', () => {
|
||||
store.add('first error');
|
||||
store.add('second error');
|
||||
expect(store.errors.length).toBe(2);
|
||||
store.remove(0);
|
||||
expect(store.errors.length).toBe(1);
|
||||
expect(store.errors[0]).toBe('second error');
|
||||
});
|
||||
});
|
Reference in New Issue