mardi 20 décembre 2016

Record express api nodejs test

The goal is to have recored api tests. This test are kind of integration tests, they load the whole app with all its middlewares and intercepts the http calls and records them.

In Python world exists "WebTest" and "VCRPY" for that.

/* global describe, it */
'use strict';

const request = require('supertest');
const app = require('../../../app.js');

var path = require('path');
var tape = require('tape');
var tapeNock = require('tape-nock');

// call tapeNock with tape and an options object
var test = tapeNock(tape, {
    fixtures: path.join(__dirname, 'fixtures'),
    mode: 'record' // this is the default mode
});

describe('Version test', function() {
    this.timeout(0);

    it('test version', function(done) {
        test('record version', function(t) {
            request(app)
                .get('/hammer/version')
                .expect(200, {
                    version: '0.1.0'
                }, done);
        });
    });
});

Aucun commentaire:

Enregistrer un commentaire