0

假设我在 micro 中有这个 routes.js:

const hello = async (req, res) => {
    send(res, 200, `Hello, ${req.params.who}`);
});

module.exports = router(
    post('/hello/:who', hello),
);

我有以下测试设置,但不幸的是,我得到的是 undefined 而不是 Hello。任何想法我做错了什么?

'use strict';

const listen = require('test-listen');
const micro = require('micro');
const test = require('ava');
const got = require('got');

require('async-to-gen/register')({includes: /index\.js$/});
const app = require('./'); // eslint-disable-line import/order

test('echo back the text', async t => {
    const service = micro(app);
    const url = await listen(service);

    const res = await got(url, {
        method: 'post',
        json: true,
        headers: {'content-type': 'application/json'},
        body: JSON.stringify({text: 'Hello!'})
    });

    t.is(res.body.text, 'Hello!');
});
4

1 回答 1

0

我想它可能只是t.is(res.body, 'Hello!')

于 2018-04-21T16:11:13.457 回答