Can't add stubs to hooks
brandonsturgeon opened this issue · 1 comments
hook.Add( "Test", "Test", stub() )
assert( hook.GetTable().Test.Test ) -- Fails
I imagine this is because a stub
isn't a function, and all major hook libraries are going to run it through isfunction
.
This will probably be an issue elsewhere, too, where we need a stub
to be a function but it fails type checks.
I see three options:
- Wrap
isfunction
andtype
andTypeID
for the duration of each test? - Change our
hook
env to wrap our stub in a holder function? - Make all stubs functions and change the function metatable to make it function the same?
I prefer wrapping the major type functions, just to be thorough, but unfortunately the base hook library localizes the type functions...
So I guess we can do the first two? For now I think I'll make our hook
env wrap the stub in a holder function, with the understanding that you still can't do:
expect( hook.GetTable().Event.ListenerID ).to.equal( myStub )
After writing some hook-based tests, I've come to the conclusion that the best way to deal with this issue is to just add hooks, call hooks, and clean up any mess you made after the test completes.
(i'll still be pushing some changes that might address this issue indirectly, though)