Import members from @edx/frontend-platform/testing
The testing module provides helpers for writing tests in Jest.
- Source:
Members
(static, constant) messages
An empty messages object suitable for fulfilling the i18n service's contract.
- Source:
Methods
(static) initializeMockApp(optionsopt)
Initializes a mock application for component testing. The mock application includes mock analytics, auth, and logging services, and the real i18n service.
See MockAnalyticsService, MockAuthService, and MockLoggingService for mock implementation details. For the most part, the analytics and logging services just implement their functions with jest.fn() and do nothing else, whereas the MockAuthService actually has some behavior implemented, it just doesn't make any HTTP calls.
Note that this mock application is not sufficient for testing the full application lifecycle or initialization callbacks/custom handlers as described in the 'initialize' function's documentation. It exists merely to set up the mock services that components themselves tend to interact with most often. It could be extended to allow for setting up custom handlers fairly easily, as this functionality would be more-or-less identical to what the real initialize function does.
Example:
import { initializeMockApp } from '@edx/frontend-platform/testing';
import { logInfo } from '@edx/frontend-platform/logging';
describe('initializeMockApp', () => {
it('mocks things correctly', () => {
const { loggingService } = initializeMockApp();
logInfo('test', {});
expect(loggingService.logInfo).toHaveBeenCalledWith('test', {});
});
});
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Properties
|
- Source: