npm install -D @coca-cola/kos-test-utils@canary
In the early phases of development, before the backend services are available, it is useful to be able to develop KOS Models and UIs in isolation. This can be facilitated using the KOS Test Utilities which can enable you to mock WebSocket requests and responses without requiring the backend to be active.
The utilities will allow you to intercept requests destined for the KOS Web Socket transport and instead provide mocked responses back to the model framework.
Install the KOS Test Utilities as a dev dependency in your project
npm install -D @coca-cola/kos-test-utils@canary
Create a new file in your project (src/mockHandlers.ts) initialize the mock websocket utility by calling the initHandlers
function passing the list (currently empty) of request handlers.
The call to initHandlers
can be wrapped in a check for an environment variable such as whether the application is running in DEV or PROD to determine if the handlers should be initialized.
import { initHandlers } from "@coca-cola/kos-test-utils";
const handlers = {};
initHandlers(handlers);
Before initializing the KOS Core (i.e. index.tsx) import the mock handlers to activate the test utilities.
import "./mockHandlers";
With this minimal configuration, your application should be able to get past the initialization phase, and you should see your content.