Node.js testing RESTful API (vows.js?)

后端 未结 3 880
深忆病人
深忆病人 2021-02-15 15:14

I could really do with some advice on testing a RESTful api I created in node.js. There are a plethora of frameworks out there and I am at a loss. My testing knowledge isn\'t go

3条回答
  •  北海茫月
    2021-02-15 15:48

    Update 6 months later

    vows-is sucks. use mocha

    Original

    Updated with vow-is code

    Here's the vows-is example from the vows-is examples folder.

    // 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();
    })
    

    This uses vows-is.

提交回复
热议问题