如何为以下代码编写茉莉花测试?

时间:2016-09-09 05:01:40

标签: javascript node.js express testing jasmine

var express = require('express');
var items = require('json-fs-store')('src/unit');
var router = express.Router();

router.get('/things', function(req, res, next) {
    items.list(function(err, things) {
        if (err) throw err;
        res.render('factories', {companyList: things}); // Render factories.ejs
    });
});

module.exports = router;

我有一个像这样的代码。当get请求被发送到服务器时,json文件数组将被发回。我有一个像这样的代码。当get请求被发送到服务器时,json文件数组将被发回。谢谢大家!

'use strict';

var request = require('supertest');

describe('Things', function () {
    var app;
    beforeEach(function () {
        app = require('../app.js');
    });
    afterEach(function () {
        app.close();
    });


    it('gets all things', function (done) {
        request(app)
            .get('/things')
            .expect(200)
            .end(function(err, res) {
                if (err) return done.fail(res);
                expect(res.body.length).toBeGreaterThan(0);
                done(res);
            });
    });
});

0 个答案:

没有答案