By DeepSource

Found useless assertions in test JS-W1039

Bug risk

When testing your application with libraries like Jest, Mocha, or Vitest, it is common to use the expect function to create assertions.

However, an assertion is only useful if it actually verifies some property of the code. For example:

expect(add(1, 2)).to.equal(2) // <- useful.
expect(add(3, 4)) // <- does not do anything.

Bad Practice

// this does not assert anything on the value returned by strip.
expect(strip("   injuly"))


// in vitest and chai:
expect(strip("   injuly")).to.equal("injuly")
// in jest:
expect(strip("   injuly")).toStrictEqual("injuly")

// Or, if you want to test that `strip` doesn't throw:
expect(() => strip("  injuly")).to.not.throw();