Cover no-op functions with Jest and Enzyme

Viewed 1185

In my React component I have some no-op functions, which basically is just placeholders for a functions. I have Istanbul test coverage, and it's complain on no-op function coverage: enter image description here

Is there any ways to cover it?

1 Answers

To make Instanbul ignore noop functions we can use /* istanbul ignore next */ mentioned here.

For you example coverage, you could do something like

const defaultContext = {
  activeInput: null,
  removeFocus: /* istanbul ignore next */ () => {},
  focusInput: /* istanbul ignore next */ () => {},
}

Or you could define an isolated noop function and reuse whenever needs

/* istanbul ignore next */
function noop() {}

const defaultContext = {
  activeInput: null,
  removeFocus: noop,
  focusInput: noop,
}
Related