Stubs won't play nicely in async environments (or at least, I can't work out how to do it), so I intentionally left out stubs from Async.
I'll add them here, but the onus is on the user to make sure their async tests aren't using conflicting stubs (remember, async tests run as a batch per-file, so as long as all of the tests in a single file play nicely, it should be fine.)
This also solves #14 by allowing beforeEach (but not currently beforeAll) to create and use stub()
This PR was tested with a full set of synchronous tests, and I tested the async functionality with this:
{
name = "Async test",
async = true,
timeout = 2,
func = function()
local og = function() return "test1" end
local var = {
func = og
}
local funcStub = stub( var, "func" ).returns( "test2" )
timer.Simple( 1, function()
expect( var.func() ).to.equal( "test2" )
expect( funcStub ).to.haveBeenCalled()
funcStub:Restore()
end )
timer.Simple( 1.5, function()
expect( var.func ).to.equal( og )
done()
end )
end
}
Stubs won't play nicely in async environments (or at least, I can't work out how to do it), so I intentionally left out stubs from Async.
I'll add them here, but the onus is on the user to make sure their async tests aren't using conflicting stubs (remember, async tests run as a batch per-file, so as long as all of the tests in a single file play nicely, it should be fine.)
This also solves #14 by allowing
beforeEach
(but not currentlybeforeAll
) to create and usestub()
This PR was tested with a full set of synchronous tests, and I tested the async functionality with this: