6.0.2 • Published 1 year ago

cds-jest v6.0.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

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

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

CHANGELOG

LICENSE

6.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago