Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fake signalR connection for unit test

We have a webservice which provides real time data for our application. In order to connect to that webservice we use $.connection. Code for that will be like -

this.myConnect = $.connection(myURL);
this.myConnect.start(settingsWhichIncludesACallBack).fail(anotherfunction);

How can I spy on the start and connection method. In other words, I don't want to establish an actual connection to the webService but still would like that my callback (passed as settings) to be call.

I am trying to use Jasmine spies to call fake for $.connection but for obvious reasons it fails on this.myConnect.start as 'not a function' for type error.

like image 538
TypeScripter Avatar asked Sep 08 '25 06:09

TypeScripter


1 Answers

I've ran into this same issue before and used this article to create a mock signalR client. I actually copied the exact script from that site and included the mock in my config instead of the actual signalR client. The article has a decent write up on how he used the mock to write unit tests and there is a link at the bottom to some examples of unit tests that the author wrote using the mock client.

like image 162
tehbeardedone Avatar answered Sep 10 '25 14:09

tehbeardedone