Skip to content

assert.stub/spy do not accept a function argument #3

Description

@mliszcz

This is an example taken directly from busted documentation:

    local t = {
      greet = function(msg) print(msg) end
    }

    stub(t, "greet")

    t.greet("Hey!") -- DOES NOT print 'Hey!'
    assert.stub(t.greet).was.called_with("Hey!")

Lua LS gives the following error on the assertion line:

Diagnostics:                                                        
Cannot assign `function` to parameter `luassert.spy`.               
- `function` cannot match `luassert.spy`                            
- Type `function` cannot match `luassert.spy` [param-type-mismatch]

I'm not sure how to fix this. Changing the param in the meta file to luassert.spy|function may be a workaround but would not be accurate. The problem is that t.greet is already a luassert.spy object but the language server incorrectly assumes that it is a function. The object is modified in-place and after the call:

local s = stub(t, "greet")

t.greet is no longer a function but a callable table. Both s and t.greet point to the same object (of type luassert.spy). It would be best if the language server could figure this out.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions