Skip to content

Enhance Mocking: Allow it to work without direct access to Serialport instance #1452

Open
@Apollon77

Description

@Apollon77
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions