mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add tests for ComposableObservableStore
This commit is contained in:
parent
4780f825b1
commit
8974f933fc
@ -12,7 +12,7 @@ class ComposableObservableStore extends ObservableStore {
|
|||||||
* @param {Object} [config] - Map of internal state keys to child stores
|
* @param {Object} [config] - Map of internal state keys to child stores
|
||||||
*/
|
*/
|
||||||
constructor (initState, config) {
|
constructor (initState, config) {
|
||||||
super()
|
super(initState)
|
||||||
this.updateStructure(config)
|
this.updateStructure(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
test/unit/ComposableObservableStore.js
Normal file
35
test/unit/ComposableObservableStore.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
const assert = require('assert')
|
||||||
|
const ComposableObservableStore = require('../../app/scripts/lib/ComposableObservableStore')
|
||||||
|
const ObservableStore = require('obs-store')
|
||||||
|
|
||||||
|
describe('ComposableObservableStore', () => {
|
||||||
|
it('should register initial state', () => {
|
||||||
|
const store = new ComposableObservableStore('state')
|
||||||
|
assert.strictEqual(store.getState(), 'state')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should register initial structure', () => {
|
||||||
|
const testStore = new ObservableStore()
|
||||||
|
const store = new ComposableObservableStore(null, { TestStore: testStore })
|
||||||
|
testStore.putState('state')
|
||||||
|
assert.deepEqual(store.getState(), { TestStore: 'state' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should update structure', () => {
|
||||||
|
const testStore = new ObservableStore()
|
||||||
|
const store = new ComposableObservableStore()
|
||||||
|
store.updateStructure({ TestStore: testStore })
|
||||||
|
testStore.putState('state')
|
||||||
|
assert.deepEqual(store.getState(), { TestStore: 'state' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return flattened state', () => {
|
||||||
|
const fooStore = new ObservableStore({ foo: 'foo' })
|
||||||
|
const barStore = new ObservableStore({ bar: 'bar' })
|
||||||
|
const store = new ComposableObservableStore(null, {
|
||||||
|
FooStore: fooStore,
|
||||||
|
BarStore: barStore,
|
||||||
|
})
|
||||||
|
assert.deepEqual(store.getFlatState(), { foo: 'foo', bar: 'bar' })
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user