UNPKG

@truenorthit/d365-webresources-setup

Version:

Scaffolds a new WebResources project for D365.

41 lines (33 loc) 1.36 kB
import ExampleWebResource from '../src/example'; describe('ExampleWebResource', () => { let formContextMock: { ui: { setFormNotification: jest.Mock } }; let executionContextMock: { getFormContext: jest.Mock }; beforeEach(() => { // create a mock ui with a jest.fn() for setFormNotification formContextMock = { ui: { setFormNotification: jest.fn(), }, }; // executionContext.getFormContext() returns our mock formContext executionContextMock = { getFormContext: jest.fn(() => formContextMock), }; }); it('should call formContext.ui.setFormNotification with the correct parameters', () => { const resource = new ExampleWebResource(); resource.onLoad(executionContextMock as any); // verify getFormContext was called expect(executionContextMock.getFormContext).toHaveBeenCalled(); // verify setFormNotification args expect(formContextMock.ui.setFormNotification).toHaveBeenCalledWith( 'This is a notification from the Example Web Resource.', 'INFO', 'exampleNotification' ); }); it('should attach itself to the window object', () => { // the module file does: (window as any).ExampleWebResource = ExampleWebResource expect((window as any).ExampleWebResource).toBe(ExampleWebResource); }); });