Skip to content

Start a test server inside describe #1068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions node.js/cds-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ Authorization: Basic alice:

### Using Jest or Mocha

[*Mocha*](https://mochajs.org) and [*Jest*](https://jestjs.io) are the most used test runners at the moment, with each having its user base.
The `cds.test` library is designed to write tests that run with both, as in this sample:
[*Mocha*](https://mochajs.org) and [*Jest*](https://jestjs.io) are the most used test runners at the moment, with each having its user base.

The `cds.test` library is designed to allow you to write tests that can run with both. Here's an example:

```js
describe('my test suite', ()=>{
Expand All @@ -120,15 +121,14 @@ describe('my test suite', ()=>{
})
})
```
> To ensure that your tests run with both `jest` and `mocha`, start a test server with `cds.test(...)` inside a `describe` block of the test.

You can use Mocha-style `before/after` or Jest-style `beforeAll/afterAll` in your tests, as well as the common `describe, test, it` methods. In addition, to be portable, you should use the [Chai Assertion Library's](#chai) variant of `expect`.

::: tip [All tests in *cap/samples*](https://github.com/sap-samples/cloud-cap-samples/blob/master/test) are written in that portable way. <br>
Run them with `npm run jest` or with `npm run mocha`.
:::



### Using Test Watchers

You can also start the tests in watch mode, for example:
Expand Down