Description
- SerialPort Version: 6.0.4
- NodeJS Version: 6/8
- Operating System and Hardware Platform: not relevant
I tried to add testing for a library that uses Serialport "inside". (https://github.com/hobbyquaker/cul). So I tried out the mocking possibilties and in general they are great, BUT in order to emit data or get the lastWrite I need access to the instance of Serialport used "inside" the library because i need to call e.g. serialportinstance.binding.lastWrite
The library itself normally do not expose the used instance to the outside world and because of struct mode and such I also can not simply access it from the outside.
So for now I ended up in adding a "getSerialport()" method to the library to return the instance ... but to have this only to allow testing feels weired :-(
Would it be possible to enhance the Mock class in a way that I can access the "connected serialport instance for a defined port" using astatic method? Something like
MockBinding.getConnectedInstance('WHATEVER_PORT_NAME');
or maybe already
MockBinding.getMockBindingForCinnectedInstance('WHATEVER_PORT_NAME');
to get directly the "serialportinstance.binding" instance to then use the methods on that in my "Outside tests".
That would really help, because so you can design the libraries without testing "backdoors" ...
Ingo