Unit testing your JavaScript
Nowadays, automated unit testing has become the norm on most projects. Unit testing is not only great at ensuring that your code is repeatedly and thoroughly tested, but it also provides a safety harness against future changes that might break your code. Furthermore, unit testing helps you improve code structure quality by building loosely coupled modules.
In this recipe, we will write a Visual Studio unit test for our Dynamics 365 JavaScript extension. More specifically, we will unit test the first JavaScript library we built in this chapter. We will check whether the conditions are correct and that the set value is called once on the postgraduatestartdate
attribute. Given that the unit tests will run from Visual Studio with a fake Xrm.Page
library, we won't need access to Dynamics 365.
Getting ready
Unlike managed .NET code unit tests, JavaScript unit testing requires a bit of preparation to get up and running. There are a few parts to your setup: you will need...