Write tests for HTTP status codes in Insomnia
After you add a collection, you can create a new test suite for the collection and then use the default Javascript test.
Create a test suite
Before we create a test, we need to create a test suite for our collection.
To do this, click the Tests tab and click New test suite in the sidebar.
Create an HTTP status code test
We can create a test that checks a request against a certain status code.
From the Test Suite we just created, click New test. Insomnia creates a default Return 200
request:
const response1 = await insomnia.send();
expect(response1.status).to.equal(200);
Validate
We can validate that our test works by testing a request.
From the Select a request drop down, select the GET KongAir planned flights request.
- Click the Play icon next to the test. In the preview to the right, you should see that the test passes.
Cleanup
Clean up Insomnia
If you created a new Collection and want to delete it, navigate to the collection, click it’s name in the sidebar on the right, and then select Delete.