|
var request = require('supertest'), |
|
app = require('./app'), |
|
myModule = require('./myModule'), |
|
defaultString = "It Works", |
|
testString = "This is my Test String" |
|
; |
|
|
|
describe("the Server", function() { |
|
it("starts", function(done) { |
|
request(app) |
|
.get("/") |
|
.expect(200) |
|
.end(done) |
|
; |
|
}); |
|
}); |
|
|
|
describe("middleware", function() { |
|
it("returns the default string", function(done) { |
|
myModule(null, function callback(error, result) { |
|
if (error) { |
|
throw error; |
|
} |
|
if (result != defaultString) { |
|
throw new Error("Expected String to Be ["+defaultString+"], Got ["+result+"]"); |
|
} |
|
done(); |
|
}); |
|
}); |
|
|
|
it("returns the test string", function(done) { |
|
myModule(testString, function callback(error, result) { |
|
if (error) { |
|
throw error; |
|
} |
|
if (result != testString) { |
|
throw new Error("Expected String to Be ["+testString+"], Got ["+result+"]"); |
|
} |
|
done(); |
|
}); |
|
}); |
|
|
|
it("returns the test string in dot notation", function(done) { |
|
myModule({text: testString}, function callback(error, result) { |
|
if (error) { |
|
throw error; |
|
} |
|
if (result != testString) { |
|
throw new Error("Expected String to Be ["+testString+"], Got ["+result+"]"); |
|
} |
|
done(); |
|
}); |
|
}); |
|
|
|
it ("errors when an array is passed", function(done) { |
|
myModule([1,2,3,4,5], function callback(error, result) { |
|
if (!error) { |
|
throw new Error("Expect an error"); |
|
} |
|
done(); |
|
}); |
|
}); |
|
|
|
it ("errors when an array is passed in dot notation", function(done) { |
|
myModule({text: [1,2,3,4,5]}, function callback(error, result) { |
|
if (!error) { |
|
throw new Error("Expect an error"); |
|
} |
|
done(); |
|
}); |
|
}); |
|
}); |