How to avoid Jest warnings: A "describe" callback must not return a value?

I guess if you really want to keep your existing test syntax and just want to avoid the warning you can do this:

const realDescribe = describe;
describe = ((name, fn) => { realDescribe(name, () => { fn(); }); });

Just add that code to a module included in your setupFilesAfterEnv and it will run "immediately after the test framework has been installed in the environment" and "before each test".

The above code will set the global describe to a function that calls the real describe but wraps the function parameter in an anonymous function that doesn't return anything.


This problem also shows up if you're using global functions that Jest v24 doesn't recognize. I'm converting some Mocha tests to Jest, and Mocha's before() was throwing the same error:

A "describe" callback must not return a value. Returning a value from "describe" will fail the test in a future version of Jest.

The stack trace pointed to describe() being the culprit, but the fix was converting the nested before() calls to a Jest-compatible beforeAll(). There might be a related issue here with trying to use it() instead of test(), but that might be grasping, there's definitely an it() in Jest's test environment.