Skip to content

Add eslint rule to restrict usage of toBeTruthy or toBeFalsy

Context

In frontend testing guide:

Avoid using toBeTruthy or toBeFalsy

Jest also provides following matchers: toBeTruthy and toBeFalsy. We should not use them because they make tests weaker and produce false-positive results.

For example, expect(someBoolean).toBeFalsy() passes when someBoolean === null, and when someBoolean === false.

What does this MR do and why?

  • Update eslint-plugin-jest to 23.20.0
  • Add rule to restrict usage of toBeFalsy and toBeTruthy in spec/frontend/.eslintrc.yml
  • Avoid usage of toBeTruthy/toBeFalsy in spec/frontend/__helpers__/class_spec_helper.js #369616 (closed)

Screenshots or screen recordings

Screenshot_from_2022-09-22_00-33-05

How to set up and validate locally

  1. Checkout branch ali_o_kan/gitlab:374983-add-rule-to-restrict-usage-of-tobetruthy-or-tobefalsy
  2. Use toBeFalsy or toBeTruthy in spec/frontend test

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to &8422 (closed)

Edited by Laurent Deketelaere

Merge request reports

Loading