Test Support for CAP Node.js
npm install @cap-js/cds-testThis is a library with test utilities for CAP Node.js applications, like
- Starting and stopping a CAP server before and after tests
- A bound HTTP client for the server
- chai-like assertion helpers
In your application project, just install the package as dev dependency:
``sh`
npm add -D @cap-js/cds-test
Add a simple test file test/bookshop.test.js with this content:`js
const cds = require('@sap/cds')
describe('Sample tests', () => {
const { GET, expect } = cds.test (__dirname+'/..')
it('serves Books', async () => {
const { data } = await GET /odata/v4/catalog/Books`
expect(data.value.length).to.be.greaterThanOrEqual(5)
})
})
Run it with Jest, for example:
`sh`
npx jest
node --test and mocha runners are supported, too, though with less coverage in real-life projects.
See the CAP documentation on cds.test` for more.
This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.
Copyright 2024-2025 SAP SE or an SAP affiliate company and cds-test contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.