We strongly recommend the utilization of Unit Testing practice. In Dynamics Mobile we are fans of Test Driven Development approach, where the unit testing practice is taken further by implementing unit tests first and then satisfying the developed and failing tests by implementing the actual functionality.
Dynamics Mobile Apps development cycle can be augmented further with unit test phase, easily by utilizing any of the publicly available unit test frameworks and compagnian tools, including but not limited to:
The createView method accepts the following arguments:
viewClass: View class declared in your project
viewHtml: Corresponding html content of the view
skipDatabind: optional, defines if the data binding phase must be skipped.
The method creates instance if the given view and executes the "view loading" part of the view lifecycle, which emulates the behavior of the view when displayed on the screen. This process will effectively call the constructor of the view and the load, resume and show methods if available. It will also execute all @input decorators and data-binding and requiring the developer to pass any hard-required input for the via via ContextService or ConfigurationService.
The view MyView has one observable member called myVar - MyView.ts, line #6.
myVar is marked as @input - supposed to be received form the context. The myVar member is also rendered in the UI via databind in MyView.html , line #6.
We can use the following JEST unit test to test our view
import { TestHelper, ContextService } from"@dms";import*as fs from"fs";import*as sinon from"sinon";import { MyView} from"../../src/Views/MyView";let sandbox:sinon.SinonSandbox;describe("MyView Task", () => {//reset sandbox before each testbeforeEach(async () => {if (!sandbox) sandbox =sinon.createSandbox();elsesandbox.restore();localStorage.clear();sessionStorage.clear(); });//reset sandbox after each testafterEach(() => {sandbox.restore(); });//this is the actual test of the viewit("MyView View",async () => {//set myVar vairable, which is required by the viewconstcontextService=RootDIContainer.inject(ContextService);awaitcontextService.set('myVar',123);//load the view's htmlconstviewHtml=fs.readFileSync("./src/Views/MyView.html","utf8" );//create view instance and execute the view loading sequenceconstmyViewInstance= (awaitTestHelper.createView( MyView, viewHtml )) asChangeTheme;//call validate method and test the resultconstvalidated=awaitmyViewInstance.validate();expect(validated).toBeTruthy();//call commit method and test the result constcommited=awaitmyViewInstance.confirm();expect(commited).toBeTruthy();//call other view method and test the result constvalue=awaitmyViewInstance.getValue();expect(commited).toBe(123); });});