reedx
Version:
Like redux but with less code
52 lines (39 loc) • 1.48 kB
JavaScript
import { Map } from 'immutable'
import { keys, values, every, isFunction } from 'lodash'
import createSelectors, { getInState } from '../createSelectors'
test('getInState()', () => {
expect(getInState({ foo: 'foo' }, 'foo')).toBe('foo')
expect(getInState(Map({ foo: 'foo' }), 'foo')).toBe('foo')
expect(getInState('foo', 'foo')).toBe('foo')
})
test('one unique selector if model has not properties', () => {
const name = 'counter'
const state = 0
expect(keys(createSelectors(name, { state }))).toEqual(['counter'])
})
test('multiple selectors in a object state', () => {
const name = 'test'
const state = {
foo: 'foo',
bar: 'bar'
}
const globalState = { test: { foo: 'foo', bar: 'bar' } }
const selectors = createSelectors(name, { state })
expect(keys(selectors)).toEqual(['foo', 'bar'])
expect(every(values(selectors), (val) => isFunction(val))).toBeTruthy()
expect(selectors.foo(globalState)).toBe('foo')
expect(selectors.bar(globalState)).toBe('bar')
})
test('multiple selectors with immutable', () => {
const name = 'test'
const state = Map({
foo: 'foo',
bar: 'bar'
})
const globalState = Map({ test: { foo: 'foo', bar: 'bar' } })
const selectors = createSelectors(name, { state })
expect(keys(selectors)).toEqual(['foo', 'bar'])
expect(every(values(selectors), (val) => isFunction(val))).toBeTruthy()
expect(selectors.foo(globalState)).toBe('foo')
expect(selectors.bar(globalState)).toBe('bar')
})