cds-jest
TypeScript icon, indicating that this package has built-in type declarations

6.0.2 • Public • Published

cds jest

jest utils for cds

npm node-test codecov Libraries.io dependency status for latest release

Quality Gate Status Security Rating Vulnerabilities Duplicated Lines (%)

Get Started

setup jest test cases for cds project with cds-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

  1. test with service layer
    1. without express server setup
    2. with a dummy mock database, you should provide the mock value for each database execution
    3. automatically connect to all application services

Features

  • [x] hack serve, use the native serve logic to test
    • [ ] partial serve
  • [ ] custom CQN matcher
    • [x] basic table matcher
    • [ ] axios response matcher (response code, body)
  • [ ] cds test wrapper (with axios type definition)

CHANGELOG

LICENSE

Readme

Keywords

Package Sidebar

Install

npm i cds-jest

Weekly Downloads

1

Version

6.0.2

License

Apache-2.0

Unpacked Size

655 kB

Total Files

27

Last publish

Collaborators

  • suntao