Skip to content

Pairing with nexdk

shamock has no dependency on nexdk. Nothing in nexdk calls shamock for you: mocking is an application choice.

Any nexdk resource declared with defineResource has a schema, so it already satisfies MockableResource.

Terminal window
import { parseMockList } from 'shamock'
import { sdk } from './sdk'
import { product } from './resources'
async function getProducts(useMock = false) {
if (useMock) {
return parseMockList(product, [{ id: 1, name: 'Demo product', price: 9.99 }])
}
return sdk.lomkit.products.get({})
}

The mock intercepts the call and answers with the JSON you seed, following shamock’s documented request protocol (search, mutate, delete): POST /<resource>/search, POST /<resource>/mutate and DELETE /<resource>. Add profile: 'lomkit' only if you need the stricter compatibility behavior. Install it before the SDK sends requests, with the SDK’s absolute base URL:

Terminal window
import { installMock } from 'shamock'
const mock = await installMock({
baseUrl: 'https://api.example.com',
seed: { products: [{ id: 1, name: 'Demo product', price: 9.99 }] },
resources: { products: product },
})
mock.restore()

While installed, requests under baseUrl never reach the network. See the Mock API for routes and limits.