示例#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)
示例#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())
示例#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)
示例#4
0
 def testShouldRaiseTypeExceptionOnInvalidReducerType(self):
     state = 1
     with self.assertRaises(TypeError):
         create("foo", state)
示例#5
0
    def testShouldHandleCreate(self):
        state = 1
        store = create(self.reducer, state)

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