Esempio n. 1
0
    def testShouldRaiseTypeExceptionOnInvalidActionType(self):
        action = {}
        state = 1
        store = create(self.reducer, state)

        with self.assertRaises(TypeError):
            store.dispatch('foo')

        with self.assertRaises(TypeError):
            store.dispatch(action)
Esempio n. 2
0
    def testShouldFireListenerOnDispatch(self):
        state = 0

        store = create(self.reducer, state)
        unsubscribe = store.subscribe(self.listener)
        self.assertTrue(callable(unsubscribe))

        store.dispatch({"type": "foo"})

        self.assertTrue(unsubscribe())
        self.assertFalse(unsubscribe())
Esempio n. 3
0
    def testShouldRaiseExceptionWhenAlreadyDispatching(self):
        _state = 1
        _store = {"store": create(self.reducer, _state)}
        store = _store["store"]

        def reducer(state, action):
            store.dispatch(action)
            return state

        with self.assertRaises(RuntimeError):
            store.replace_reducer(reducer)
Esempio n. 4
0
 def testShouldRaiseTypeExceptionOnInvalidReducerType(self):
     state = 1
     with self.assertRaises(TypeError):
         create("foo", state)
Esempio n. 5
0
    def testShouldHandleCreate(self):
        state = 1
        store = create(self.reducer, state)

        self.assertEqual(store.get_state(), state + 1)