lundi 30 mars 2015

Running node tests with tape


Vote count:

0




I'm using tape and I'm trying to test a couple of functions. My functions throw errors and validate objects. I like throwing errors because then later my promises can catch them. I'm trying to run simple tests and establishing the data argument in all the scenarios to hit each error in the stack. How can I test this function without putting it in a try / catch every time? I see there's two functions in the API t.throws() and t.doesNotThrow() , I've tried them both and even added the extra params like t.throws(myFunc({}), Error, "no data") but nothing seems to work as expected.



var test = require('tape')
var _ = require('underscore')

function myFunction(data){
if(!data) throw new Error("no data")
if(_.size(data) == 0) throw new Error("data is empty")
if(!data.date) throw new Error("no data date")
if(!data.messages.length == 0) throw new Error("no messages")
data.cake = "is a lie"
return data
}

test("my function", function(t){
t.plan(1)
t.throws(myFunction({}))
}


asked 47 secs ago







Running node tests with tape

Aucun commentaire:

Enregistrer un commentaire