Jest: mockFn.mock.results is always undefined

Created on 7 Jul 2018  路  4Comments  路  Source: facebook/jest

馃悰 Bug Report

mockFn.mock.results is always undefined

To Reproduce

Steps to reproduce the behavior:

    const temp = jest.fn(() => 10);
    temp(1);
    temp(2);
    console.log(temp.mock)

I tested it in my project and here https://jestjs.io/#use

Expected behavior

temp.mock.results === [{
    value: 10
  }, {
    value: 10
  }]

Most helpful comment

Sorry, I found out that this functionality exists in 23+ version

All 4 comments

Sorry, I found out that this functionality exists in 23+ version

Anyone know if it's possible to see the result of a spy using Jest 20.0.4, which comes with create-react-app?

That's not possible, the feature was added in jest 23.0.0.

You have to track it yourself

let returnValues = [];

jest.fn(() => {
  const returnThingy = someFunc();

  returnValues.push(returnThingy);

  return returnThingy;
});

Thanks. A spy that won't tell me what he found? Sounds like a double-agent...

Was this page helpful?
0 / 5 - 0 ratings