Jabran Saeed
Jabran Saeed

Reputation: 6168

importing reducer/action in jest throwing error

My jest tests work fine with components. However on importing an action it throws the following error with errors pointing to react-dom mount methods.

Invariant Violation: _registerComponent(...): Target container is not a DOM element.

ReactDom is being called in some other tests, but even after removing it, error persists.

On importing reducer following is thrown

 Expected the reducer to be a function.

Meanwhile, minimal code to recreate this looks like

import { someAction } from './actions';

Upvotes: 1

Views: 435

Answers (1)

Jabran Saeed
Jabran Saeed

Reputation: 6168

Found the answer here

Basically you need

jest.mock("./index.js", () => "root");

Im not entirely sure why test suite would fail because we're not using DOM while testing actions/reducers.

Upvotes: 1

Related Questions