B
B
bpGusar2018-10-31 19:01:40
Software testing
bpGusar, 2018-10-31 19:01:40

How to test a function that returns createStore?

There is a function in which certain actions take place, and it returns createStore, how to test it?
If it's corny to write like this, then she gives out
expect(createReduxStore(arg)).toEqual(1);

{  
   "dispatch":[  
      Function anonymous
   ],
   "getState":[  
      Function getState
   ],
   "replaceReducer":[  
      Function replaceReducer
   ],
   "subscribe":[  
      Function subscribe
   ],
   Symbol(observable):[  
      Function observable
   ]
}

And I don't know what to do with it. In which direction to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2018-10-31
@search

You absolutely do not need to test the createStore function because it is very well tested by the creators of the library and works great. There is no point in making sure that this function does what is expected of it.
But it makes sense to test your reducer function. It's very easy - just pass the state and action to the input of the reducer function and check what new state it returns.
UPD
And in general, unit testing of library code is a so-so idea. It is better to spend time testing your code.
It is very common to see programmers trying to make sure that a library correctly called their code as part of their testing. This, in fact, is again testing the library code. The process is not only useless, but also harmful. Why is it harmful? Because the programmer is busy duplicating the tests of the library, creating code that is not useful, but requires additional support time.
How to understand that the programmer is busy testing the library, and not his code? By the abundance of mocks, stubs, state presets, state resets and increased complexity of tests in general. The left hand rule is this: if at first glance it is impossible to understand what a function is testing, then this means that it does not test anything, but eats up time for support.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question