Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6476173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:47:32+00:00 2026-05-25T06:47:32+00:00

How can I test a function like this? app.post ‘/incoming’, (req,res) -> console.log Hello,

  • 0

How can I test a function like this?

app.post '/incoming', (req,res) ->
    console.log "Hello, incoming call!"
    message = req.body.Body
    from = req.body.From

    sys.log "From: " + from + ", Message: " + message
    twiml = '<?xml version="1.0" encoding="UTF-8" ?>\n<Response>\n<Say>Thanks for your text, we\'ll be in touch.</Say>\n</Response>'
    res.send twiml, {'Content-Type':'text/xml'}, 200

I haven’t chosen any test framework yet. I don’t understand how this can be tested.

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:47:32+00:00Added an answer on May 25, 2026 at 6:47 am

    Testing is simple. You just create a unit test that starts your express server, makes a http POST and asserts that your HTTP post works and gets the correct output back.

    Using vows-is. (Sorry, no coffeescript)

    var is = require("vows-is"),
        app = require("../src/app.js");
    
    is.config({
        "server": {
            "factory": function _factory(cb) { cb(app); }
        }
    });
    
    is.suite("http request test").batch()
    
        .context("a request to POST /incoming")
            // make a POST request
            .topic.is.a.request({
                "method": "POST",
                "uri": "http://localhost:8080/incoming",
                // set the request body (req.body)
                "json": {
                    "Body": ...,
                    "From": ...
                }
            })
            .vow.it.should.have.status(200)
            .vow.it.should.have
                .header("content-type", "text/xml")
            .context("contains a body that")
                .topic.is.property('body')
                .vow.it.should.be.ok
                .vow.it.should.include.string('<?xml version="1.0" encoding="UTF-8" ?>\n<Response>\n<Say>Thanks for your text, we\'ll be in touch.</Say>\n</Response>')
    
    // run the test suite
    .suite().run({
        reporter: is.reporter
    }, function() {
        is.end();
    });
    

    Store this in a file http-test.js in a folder test. Then just run

    $ npm install vows-is
    $ node test/http-test.js
    

    See an example of exporting your serverSetup function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As topic suggested, how can I unit test a function that does not return
In most languages like C# for example given a string you can test (boolean)
I've done this simple app in Gtk, just to test things out... I come
I’m writing a Dashcode app that contains a list. I’d like to populate this
I can run this code in Android app (using PhoneGap adn jQuery Mobile) but
I would like to create a debugging helper function which I can use within
I have a VSTO Excel workbook that functions correctly in test. I can deploy
I wonder if I can test landscape view using simulator?
It is my understanding that I can test that a method call will occur
Is there a way I can test if there are any other activities in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.