microsoft / TypeScript-React-Starter

A starter template for TypeScript and React with a detailed README describing how to use the two together.
MIT License
11.09k stars 1.21k forks source link

Issues when unit testing Reducer #236

Open hypr2771 opened 6 years ago

hypr2771 commented 6 years ago

Hi,

first of all, I appreciate a lot your work and your sharing. I also doubt it's due to the project as is, but I am running into an error when trying to unit test Adding a reducer as suggested.

My test is the following

// src/reducers/index.test.tsx

import {EnthusiasmAction, incrementEnthusiasm} from "../actions";
import {IStoreState}                           from "../types";
import {enthusiasm}                            from "./index";

it('reducers should increment state', cb => {
  const givenState: IStoreState = {
    enthusiasmLevel: 1,
    languageName: 'JavaScript'
  }

  const action: EnthusiasmAction = incrementEnthusiasm()

  const expectedState: IStoreState = {
    enthusiasmLevel: 2,
    languageName: 'JavaScript'
  }

  expect(enthusiasm(givenState, action))
    .toEqual(expectedState)
})

and the error is the following

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

    at pTimeout (/home/castelluciv/Workspace/Project/Marketplace/marketplace-front/node_modules/jest-jasmine2/build/queueRunner.js:53:21)
    at Timeout.setTimeout (/home/castelluciv/Workspace/Project/Marketplace/marketplace-front/node_modules/jest-jasmine2/build/p-timeout.js:21:44)
    at listOnTimeout (timers.js:324:15)
    at processTimers (timers.js:268:5)

I have read StackOverflow and GitHub issues about it but my instinct and my past experiences with asynchronous frameworks suggest me something is not yet terminated (while people mostly suggest increasing Jasmine timeout), so I guess I am doing something wrong.