JSPM

@serenity-js/rest

2.0.1-alpha.37
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14614
  • Score
    100M100P100Q139563F
  • License Apache-2.0

Test REST APIs with Serenity/JS

Package Exports

  • @serenity-js/rest

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@serenity-js/rest) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Serenity/JS

Serenity/JS is a node.js library designed to make acceptance and regression testing of modern full-stack applications faster, more collaborative and easier to scale.

Serenity/JS REST

The @serenity-js/rest module let's you interact with and test HTTP REST APIs.

Learn more at serenity-js.org!

Example test

import { Actor } 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 = Actor.named('Apisit').whoCan(CallAnApi.at('https://myapp.com/api'));

actor.attemptsTo(
    // no users present in the system
    Send.a(GetRequest.to('/users')),
    Ensure.that(LastResponse.status(), equals(200)),
    Ensure.that(LastResponse.body(), equals([])),

    // create a new test user account
    Send.a(PostRequest.to('/users').with({
        login: 'tester',
        password: 'P@ssword1',
    }),
    Ensure.that(LastResponse.status(), equals(201)),
    Ensure.that(LastResponse.header('Location'), startsWith('/users')),

    // delete the test user account
    Send.a(DeleteRequest.to(LastResponse.header('Location'))),
    Ensure.that(LastResponse.status(), equals(200)),
);