cds jest
jest utils for
cds
Get Started
setup
jest
test cases for cds project withcds-jest
Quick View
describe('serve Test Suite', () => {
const { serve } = require("cds-jest");
const cds = require("@sap/cds");
const run = serve()
it('should support connect to simple service', async () => {
const ps = await cds.connect.to("PersonService")
expect(ps).toBeInstanceOf(cds.Service)
expect(ps).not.toBeUndefined()
expect(jest.isMockFunction(ps.run)).toBeTruthy() // is spied function
});
it('should support connect and consume data', async () => {
const PersonService = await cds.connect.to("PersonService")
const query = INSERT.into("Person").entries([{ ID: "773096ac-63fb-4943-8a45-5b3837a9ed8e", Name: "Theo Sun" }])
const result = await PersonService.run(query) // execute request
expect(result).toMatchObject({
Name: "Theo Sun"
})
expect(run.mock.lastCall).toMatchInlineSnapshot(`
Array [
INSERT {
"INSERT": Object {
"entries": Array [
Object {
"ID": "773096ac-63fb-4943-8a45-5b3837a9ed8e",
"Name": "Theo Sun",
},
],
"into": "PersonService.Person",
},
},
Object {
"ID": "773096ac-63fb-4943-8a45-5b3837a9ed8e",
"Name": "Theo Sun",
},
]
`)
});
});
Samples
-
test with service layer
- without
express
server setup - with a dummy mock database, you should provide the mock value for each database execution
- automatically connect to all application services
- without
Features
- [x] hack
serve
, use the native serve logic to test- [ ] partial
serve
- [ ] partial
- [ ] custom CQN matcher
- [x] basic table matcher
- [ ] axios response matcher (response code, body)
- [ ] cds test wrapper (with axios type definition)