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
import test, expect from "wowlua:test" @test("counts")local function counts() local count = 3 expect(count).toHaveLength(3)endimport test, expect from "wowlua:test" @test("counts")local function counts() local items = { "a", "b", "c" } expect(items).toHaveLength(3)endThe 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
Related codes
| code | message |
|---|---|
| E2001 | Type mismatch: S is not assignable to T |
Offline
$ wowlua explain E8121 E8121 (error): A matcher used on a value of a kind it does not take (toHaveLength on a number)