user-preferences
An abstraction layer that provides user preferences (like theme, language etc.) from environment on which the app is run.
Unit testing app using user-preferences
package with jest
Prerequisite
Add in your jest.config.js
file entry with @dynatrace-sdk/user-preferences/testing
setup:
setupFiles: ['@dynatrace-sdk/user-preferences/testing]
Configuring user-preferences
mock
Testing package comes with some default mocked values.
For example if you use getTheme()
function it will return auto
string value.
There is also option to provide custom values and mocked functions:
import { mockUserPreferences } from '@dynatrace-sdk/user-preferences/testing';
const getThemeMock = () => 'dark';
mockUserPreferences({
getTheme: getThemeMock,
});
With such configuration getTheme()
will return dark
instead of default auto
value.
There will be also possibility to check for example call count of getTheme
method with jest
API: expect(getThemeMock.mock.calls.length).toBe(2);
All other user-preferences
package functions can be mocked in same way.