Hi, and welcome to API Testing, SuperTest and Nock. I'm Lewis Prescott.

In this course, you will learn to:

  • Perform GET and POST requests using SuperTest

  • Learn how to inspect the JSON response

  • Mock API calls with Nock

  • How to intercept API calls within your front-end JavaScript Framework, using React as an example. This will allow us to test components in isolation.

SuperTest is a high level abstraction of HTTP requests, making it perfect for testing APIs.

Nock is a HTTP server mocking package, allowing us to test modules that make HTTP requests.

I will introduce these concepts and set you a couple of exercises so that you can practice what you have learned.

API testing with these tools will give you the confidence that your interactions with your backend services, all your third party integrations are constructed correctly.

If you would like to have a look at the documentation for the NPM packages we are going to use, feel free to check them out. Links have been provided in the resources section.

First thing we need to do is set up our environment.

I'll be using VS Code as my IDE for the exercises, but feel free to use the text editor of your choice.

Hopefully, you have all been through the Introduction to Mocha course with Giri.

If not, no problem.

I've provided a GitHub repository with the framework already set up.

If you'd like to set up the environment from scratch, just run:


npm init

And then install these packages:

  • Mocha for our test runner
  • Chai for our assertions
  • SuperTest for our API testing
  • Nock for our mocking framework
  • Express to test our test implementation has been set up

npm install mocha chai supertest nock express



Resources

© 2024 Applitools. All rights reserved. Terms and Conditions Privacy Policy GDPR