0

I'm using JEST to test my react app.

I get the error and some text as in the image below.

enter image description here

Also, the code for my test case(named: TodoApp.test.jsx) is as :

it("should add todo ...", () => {
    // const text = "Suzal is trying react";

    // I commented out the other lines because the test
    // only gave error when this line was included.

    const todoApp = TestUtils.renderIntoDocument(<TodoApp />);

    // todoApp.state = {
    //     todos: []
    // }
    // todoApp.handleAddTodo(text);
    // expect(todoApp.state.todos[0].text).toBe(text);
});

If extra code/description is needed then please do ask. The complete file is on Github : TodoApp.test.jsx

Links that I already have gone through

doelleri
  • 19,232
  • 5
  • 61
  • 65
Pramesh Bajracharya
  • 2,153
  • 3
  • 28
  • 54

1 Answers1

0

I cloned your repo and started commenting things out and found that there seems to be something going on with TodoApi.getTodos() on line 15 of TodoApp.jsx in the constructor when setting your initial state. If you remove the call to TodoApi.getTodos and replace with with an empty array the test errors disappear. You may need to create a mock function for TodoApi.getTodos to get your tests to pass.

https://facebook.github.io/jest/docs/en/mock-functions.html

Jenna Rajani
  • 243
  • 2
  • 3