v0.13.7
errors and warnings / stdlib

errors and warnings / stdlib / E8121

E8121 error

A matcher used on a value of a kind it does not take (toHaveLength on a number)

area
stdlib (x8xxx)
fails the build
yes

A matcher is used on a kind of value it doesn't take. toHaveLength and toContain need a string or a table, toBeCloseTo a number, and toThrow and the spy matchers a function. A custom matcher made with matcher takes the type of its first parameter. Such an assertion could never pass, so check that expect gets the value you meant to test.

Example

× failstests/main.test.wowluawowlua
import test, expect from "wowlua:test" @test("counts")local function counts()    local count = 3    expect(count).toHaveLength(3)end
✓ compilestests/main.test.wowluawowlua
import test, expect from "wowlua:test" @test("counts")local function counts()    local items = { "a", "b", "c" }    expect(items).toHaveLength(3)end

The compiler reports it like this:

error[E8121]: `toHaveLength` needs a string or a table; the value is `number`
  ┌─ tests/main.test.wowlua:6:5
  │
6 │     expect(count).toHaveLength(3)
  │     ^^^^^^^^^^^^^^^^^^^^^^^^^^ here
codemessage
E2001Type mismatch: S is not assignable to T

Offline

terminal
$ wowlua explain E8121
E8121 (error): A matcher used on a value of a kind it does not take (toHaveLength on a number)

source on GitHub ↗