Skip to content

Test: Add givenMiddleware(middleware)#113

Merged
vlaurin merged 1 commit intomainfrom
112-givenmiddleware
May 19, 2021
Merged

Test: Add givenMiddleware(middleware)#113
vlaurin merged 1 commit intomainfrom
112-givenmiddleware

Conversation

@vlaurin
Copy link
Copy Markdown
Contributor

@vlaurin vlaurin commented May 18, 2021

Resolves #112

Example

import {givenMiddleware} from '@quickcase/node-toolkit/test';

test('should resolve with response when response expected', async () => {
  const middleware = (req, res) => res.status(201).json({foo: 'bar'});
  const res = await givenMiddleware(middleware).when({}).expectResponse();
  expect(res).toEqual({
    status: 201,
    body: {foo: 'bar'},
  });
});

test('should resolve with next when next expected', async () => {
  const middleware = (req, res, next) => next('error');
  const next = await givenMiddleware(middleware).when({}).expectNext();
  expect(next).toEqual('error');
});

@vlaurin vlaurin requested a review from gbenadikar May 18, 2021 16:58
@vlaurin vlaurin force-pushed the 112-givenmiddleware branch from 112d902 to 1c1d755 Compare May 18, 2021 16:59
Copy link
Copy Markdown
Contributor

@gbenadikar gbenadikar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Base automatically changed from add-test-module to main May 18, 2021 21:05
@vlaurin vlaurin force-pushed the 112-givenmiddleware branch from 1c1d755 to 1d0ad74 Compare May 18, 2021 21:06
@vlaurin vlaurin merged commit 04bcfc8 into main May 19, 2021
@vlaurin vlaurin deleted the 112-givenmiddleware branch May 19, 2021 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: givenMiddleware(middleware).then(req).expect[Response|Next]()

2 participants