TGIMBA .NET Core Upgrade – JavaScript Unit Tests with JSTest.Net – Truly Awesome!!

NOTICE: The TGIMBA git hub repository has been corrupted and I had to start over.  The link to the repository is here -> Git  Code Commit

Today, I am focusing on adding unit tests for the JavaScript I added in the last post. I looked at a number of contenders, but all of them seemed to tied to a browser or additional server or something ‘extra’. I wanted to run them just like I ran the C# server side unit tests.

I will do integration tests (some on the server as I did with the existing .NET 4.6.x code I ported over (to be replaced) and some via Selenium (also like I did in the .NET 4.6.x website)), but I wanted to focus on that a little further down the road. Ideally, that would be written along with the unit tests following a Test Driven Design (TDD) methodology, but I am anxious to explore the Graphic User Interface (GUI) perspective 🙂

I did find one contender that (so far) has met my requirements – JSTest.Net created by Chris Baxter. Locally, it was as easy to install via Nuget and my simple test worked.

  • Sample Test


  • File/Function under test


  • Running test


So, I added my tests and initially, everything worked as expected. I then tried a pipeline build and was surprised when I got an error. Upon more digging, the nuget restore of this project was not found.


This predictably caused the build to fail.


Some initial research did not reveal an easy solution, so I disabled the check in build integration and checked in and deployed the site manually. I did not want to spend a lot of time (again) dealing with the pipeline.

Then, I hit another hurdle. Injecting what I thought would have worked failed. I wanted to inject a Hyper Text Markup Language (HTML) document so my Load method could be tested whether it found my target div or not. I kepting getting errors about illegal characters. So, I actually sat down and read the documentation (only when you absolutely have to 🙂 ) and determined that the append file was only for JavaScript files. So, I decided to put that off and concentrate on true disconnected unit tests without injection.

Guided by the documentation, I was able to create unit tests for:

  • ErrorHandler.js


  • Utility.js


  • Run together


With this working, I contemplated how I could get my pipeline to work with this apparently rogue nuget package. So, I forked JSTest.Net, downloaded it and tried building it…lots of errors. I also noticed that it was no longer maintained. Given how useful this package is to me and my needs, I may attempt to get my fork compiling and working, but for now, I am going to reference the nuget .dll file (old school, I know) and store with my code. Not ideal, but it works 🙂

Adding the JSTest.dll file as a local reference and running all tests throw VS 2017 works.

Initially, the pipeline broke because of my references. I removed that test project, added a .Net Core test project (duh Eric 🙂 ), ported over my test code and voila it works 🙂

Website after build.

I would still like to figure out the injection thing so I can test my Global.js Load() method, so I will either do that or move on to the Login page.

Stay tuned!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s