Jest / Enzyme test for a React component to calculate average data speed
There are two distinct parts in your test:


Testing the rendering of AvgSpeed component.
Testing the logic of getAverage() and extractSpeeds().


This separation between components and logic is good. I would suggest separating them even more by moving the getAverage() and extractSpeeds() functions to separate file, which you can then test completely independently from the component.

The component rendering test however is dependent on the logic. That's not good:


You're re-testing the logic through the component test, which is duplication.
When there's a change in logic, the component test will also break, resulting in more work maintaining the tests.


So your component test really is more of an integration test, not a pure unit test. There are basically two ways to improve on that:


Change the component. Instead of the component importing these functions and calling them, perhaps you could perform the calculation outside of the component and just pass in download and upload props.
Change the test. Instead of letting the component call actual getAverage() and extractSpeeds() you could replace them with mock implementations. Though, the less mocking you need, the better. So, you could consider combining the two functions into one, which will be easier to mock out.


Usually the first approach is better and requires no extra tooling. If you decide to go the mocking route, my personal choice is the rewire library, of which there exist various versions for various environments (e.g. for Babel).

Regarding specific tests

Avoid temporary variables when you can write the values inline. Instead of:

expect(extractSpeeds(inputObj, downloadIn)).toEqual(downloadOut);


prefer:

expect(extractSpeeds(inputObj, "download")).toEqual([22, 24]);


Avoid logic in tests. Logic is error-prone. While hard-coded values are a big no-no in normal code, in test code they're usually OK. Instead of:

input = [1, 2, 3];
input = input.map(n =&gt; (n += 1));


just hard-code it:

input = [2, 3, 4];


Try to write one assertion (expect) per it() block. This way you can give a more descriptive name for each scenario you want to test.

Don't simply repeat the same test multiple times. For example, you're testing the getAverage with [1,2,3], [2,3,4], [3,4,5] - it's essentially the same test: three sequential numbers. Try to come up with more fundamentally different scenarios:


different lengths of array.
positive/negative numbers, fractional numbers, zero.
array of similar numbers.


Think of the edge cases:


What if there is no data? (e.g. empty object or array)
What kind of input data would be problematic? (e.g. negative numbers)