Serenity/JS
Serenity/JS is an innovative framework designed to make acceptance and regression testing
of complex software systems faster, more collaborative and easier to scale.
To get started, check out the comprehensive Serenity/JS Handbook, API documentation, and Serenity/JS project templates on GitHub.
If you have any questions or just want to say hello, join the Serenity/JS Community Chat.
Serenity/JS REST
@serenity-js/rest
module lets your actors interact with and test HTTP REST APIs.
Installation
To install this module, as well as axios
HTTP client,
run the following command in your computer terminal:
npm install --save-dev @serenity-js/{core,rest,assertions} axios
Example test
import { actorCalled } from '@serenity-js/core';
import { CallAnApi, DeleteRequest, GetRequest, LastResponse, PostRequest, Send } from '@serenity-js/rest'
import { Ensure, equals, startsWith } from '@serenity-js/assertions';
const actor = actorCalled('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));
actor.attemptsTo(
Send.a(GetRequest.to('/users')),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body(), equals([])),
Send.a(PostRequest.to('/users').with({
login: 'tester',
password: 'P@ssword1',
}),
Ensure.that(LastResponse.status(), equals(201)),
Ensure.that(LastResponse.header('Location'), startsWith('/users')),
Send.a(DeleteRequest.to(LastResponse.header('Location'))),
Ensure.that(LastResponse.status(), equals(200)),
);