Node.js测试RESTful API(vows.js?)

hen*_*ald 8 testing node.js vows

我真的可以做一些关于测试我在node.js中创建的RESTful api的建议.那里有太多的框架,我很茫然.我的测试知识一般不够好,这就是我试图编写这些测试的原因.我已经尝试了vows.js这看起来不错,但我无法弄清楚如何合并我的API的测试,我需要某种客户端.我需要一个简单的测试登录系统的帖子的例子.

Ray*_*nos 7

6个月后更新

誓言很糟糕.用摩卡

原版的

更新了vow-is代码

这是誓言 - 来自vows-is examples文件夹的示例.

// simple HTTP
// Run with node example/simple-http.js

var express = require("express");
    is = require("../src/vows-is.js");

is.config({
    "server": {
        "factory": function _factory(cb) {
            var app = express.createServer();

            app.get("/", function(req, res) {
                res.send("hello world");
            })

            app.listen(3000);

            cb(app);
        },
        "uri": "http://localhost:3000",
        "kill": function _kill(app) {
            app.close();
        }
    }
});

is.suite("http request test").batch()

    .context("a request to GET /")
        .topic.is.a.request("GET /")
        .vow.it.should.have.status(200)
        .vow.it.should.have
            .header("content-type", "text/html; charset=utf-8")
        .context("contains a body that")
            .topic.is.property('body')
            .vow.it.should.be.ok
            .vow.it.should.include.string("hello world")

.suite().run({
    reporter: is.reporter
}, function() {
    console.log("finished");
    is.end();
})
Run Code Online (Sandbox Code Playgroud)

这使用誓言.