@serenity-js/rest
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0-rc.8 • Public • Published

    Serenity/JS

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

    Visit serenity-js.org for the latest tutorials and API docs, and follow @SerenityJS and @JanMolak on Twitter for project updates.

    Learning Serenity/JS

    To learn more about Serenity/JS, check out the video below, read the tutorial, review the examples, and create your own test suite with Serenity/JS template projects.

    If you have any questions, join us on Serenity/JS Community Chat.

    Full-Stack Acceptance Testing with Serenity/JS and the Screenplay Pattern

    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(
        // 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)),
    );

    Install

    npm i @serenity-js/rest

    DownloadsWeekly Downloads

    2,476

    Version

    3.0.0-rc.8

    License

    Apache-2.0

    Unpacked Size

    233 kB

    Total Files

    82

    Last publish

    Collaborators

    • jan-molak