Snippets Collections
const mongoose = require('mongoose')
const supertest = require('supertest')
const app = require('../app')

const api = supertest(app)

test('notes are returned as json', async () => {
  await api
    .get('/api/notes')
    .expect(200)
    .expect('Content-Type', /application\/json/)
})

afterAll(() => {
  mongoose.connection.close()
})
const request = require('supertest');
const assert = require('assert');

request('https://dog.ceo')
  .get('/api/breeds/image/random')
  .expect(200) // assert HTTP status code
  .expect('Content-Type', 'application/json') // assert content type
  .expect(function(res) { // assert body JSON structure
    assert(res.body.hasOwnProperty('status'));
    assert(res.body.hasOwnProperty('message'));
  })
  .end(function(err, res) {
    if (err) throw err;
  });
star

Wed Apr 13 2022 03:51:28 GMT+0000 (Coordinated Universal Time)

#javascript #supertest
star

Fri Jan 14 2022 14:28:19 GMT+0000 (Coordinated Universal Time)

#api-testing #nodejs #supertest

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension