Jest: expect an array not containing an element

It turns out that Jest supports a matcher to expect an array that doesn't contain an element.

test("cost for a pitched roof excluded from the PV installation", () => {
  const installedProducts = ["meter", "pv-system", "site-visit"]
  expect(installedProducts).toEqual(
    expect.not.arrayContaining(["extra-cost-for-pitched-roof"])
  )
})

Would you like to connect? Subscribe via email or RSS , or follow me on Twitter!