What is the best way to mock xero-node in unit tests? #558
Replies: 2 comments
-
|
Thank you very much for the topic. I'd like to share as an example: https://www.npmjs.com/package/@elastic/elasticsearch-mock
I'm not familiar how is implemented elasticsearch-mock as a package but my expectations are if xero-node has an equivalent to be something like elasticsearch-mock |
Beta Was this translation helpful? Give feedback.
-
|
Short version: don't mock the import nock from 'nock';
nock('https://api.xero.com')
.get('/api.xro/2.0/Invoices')
.reply(200, { Invoices: [{ InvoiceID: '...', Total: 100 }] });
// call xeroClient.accountingApi.getInvoices(tenantId) and assertTests stay offline and deterministic, and you can assert on the request (URL/headers/body), not just the response. I do the same in my own MCP servers built on fetch-based APIs — contract-style tests over every request with a fetch mock — far less brittle than stubbing client objects, which break whenever the SDK shape changes. If you do want client-level stubbing, dependency-injecting |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When working with other vendor APIs, there are usually mock packages available to make writing unit tests considerably easier.
Examples:
I don't see an equivalent for
xero-node.What is the best way to mock
xero-nodein unit tests, currently?Beta Was this translation helpful? Give feedback.
All reactions