A
A
AntonHPL2021-12-12 20:10:42
React
AntonHPL, 2021-12-12 20:10:42

How to solve Cannot Destructure Property trouble in enzyme?

Test file:

import React from "react";
import DataAdmin from "../../../src/components/data-admin/DataAdmin";
import { configure, shallow } from "enzyme";
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

it("should render DataAdmin component", () => {
    const component = shallow(<DataAdmin />);
    const dataTable = component.find("DataTable");
    expect(dataTable.length).toBe(1);
});

Error: 61b62cf90a7c9706861647.png
Component Fragment:
const DataAdmin = () => {
  const {
    preparedEvents, 
    dropdownItems,
    dropdownClicked, setDropdownClicked,
    loading,
    updatedChanges, setUpdatedChanges
  } = useContext(EventsLoadingContext);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AHMED_RAPIRA, 2021-12-12
@AHMED_RAPIRA

Try passing the context to shallow :

const component = shallow(<DataAdmin />, { context: ... });

V
Vladimir, 2021-12-13
@Casufi

Your context is empty, mock it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question