socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

Cannot mock Socket

Open jeiea opened this issue 2 years ago • 0 comments

#313 changes DartySocket extension to access this.io. This makes me unable to mock Socket as described in mockito FAQ.

I'm using DartySocket.onError, and because mockito doesn't support deep stubbing when accessing io it throws the following.

FakeUsedError (FakeUsedError: 'io'
No stub was found which matches the argument of this method call:
io

A fake object was created for this call, in the hope that it won't be ever accessed.
Here is the stack trace where 'io' was called:

#0      new SmartFake (package:mockito/src/mock.dart:235:41)
#1      new _FakeManager_3 (file:///Users/jeiea/Documents/app/test/utils/test_utils.mocks.dart:105:7)
#2      MockSocket.io (file:///Users/jeiea/Documents/app/test/utils/test_utils.mocks.dart:1140:36)
#3      DartySocket.onError (package:socket_io_client/src/darty.dart:31:10)

I thought some workarounds and maybe I can bypass this by making new interface, but can it be redesigned to support mocking easily if it is possible?

jeiea avatar Jan 26 '23 08:01 jeiea