Permalink
Browse files

[dist] Rewrote tests with nodeunit.

  • Loading branch information...
1 parent b69bb47 commit 4e6e648379a262991c0a69fb1e410c16820519a5 @jfhbrook committed Sep 1, 2011
Showing with 39 additions and 33 deletions.
  1. +2 −2 README.md
  2. +1 −1 package.json
  3. +36 −30 test/test.js
View
4 README.md
@@ -53,9 +53,9 @@ Sends an email. Options are the same as those of the [sendgrid json web api](htt
In order to run the tests, sendgrid needs a user, api key, and email addresses to send to and from. Before running these tests, open `./test/config-template.json`, edit it to contain your credentials and information, and save it as `./test/config.json`.
-Then, you may run the tests with vows:
+Then, you may run the tests with nodeunit:
- vows test/*.js --spec
+ nodeunit test/*.js
**Author:** Joshua Holbrook
**Copyright 2011 Nodejitsu, Inc.**
View
2 package.json
@@ -10,7 +10,7 @@
},
"main": "lib/sendgrid.js",
"scripts": {
- "test": "vows --spec test/*.js"
+ "test": "nodeunit test/*.js"
},
"engines": {
"node": "~v0.4.9"
View
66 test/test.js
@@ -1,35 +1,41 @@
-var vows = require("vows"),
- assert = require("assert"),
+var assert = require("assert"),
Sendgrid = require(__dirname + "/../lib/sendgrid"),
fs = require("fs"),
configFile = __dirname + "/config.json",
- config = JSON.parse(fs.readFileSync(configFile));
+ config = JSON.parse(fs.readFileSync(configFile)),
+ sendgrid;
-vows.describe("Sending emails with Sendgrid").addBatch({
- "When constructing a new sendgrid object,": {
- topic: function () {
- return new Sendgrid({
- user: config.user,
- key: config.key
- });
- },
- "The resulting object has a 'send' method": function (sendgrid) {
- assert.isTrue(Object.hasOwnProperty.call(sendgrid, "send"));
- assert.equal(typeof(sendgrid.send), "function");
- },
+exports["Constructor returns object with send method"] = function (test) {
+ sendgrid = new Sendgrid({
+ user: config.user,
+ key: config.key
+ });
- "and then calling it with legitimate options": {
- topic: function (sendgrid) {
- sendgrid.send({
- to: config.to,
- from: config.from,
- subject: 'This is a test of node-sendgrid.',
- html: "<h1> This is a test of node-sendgrid.</h1><p>If you are reading this, node-sendgrid was able to send your email properly.</p>"
- }, this.callback );
- },
- "Successfully sends an email without error": function (err) {
- assert.isNull(err);
- }
- }
- }
-}).export(module);
+ test.ok(Object.hasOwnProperty.call(sendgrid, "send"));
+ test.equal(typeof(sendgrid.send), "function");
+ test.done();
+};
+
+exports["Given legitimate options, sends an email"] = function (test) {
+ sendgrid.send({
+ to: config.to,
+ from: config.from,
+ subject: 'This is a test of node-sendgrid.',
+ html: "<h1> This is a test of node-sendgrid.</h1><p>If you are reading this, node-sendgrid was able to send your email properly.</p>"
+ }, function (err) {
+ test.equal(err, null);
+ test.done();
+ });
+}
+
+exports["Given bad options, returns an error"] = function (test) {
+ sendgrid.send({
+ to: config.to,
+ from: config.from,
+ subject: 'This is a test of node-sendgrid.',
+ body: "<h1> This is a test of node-sendgrid.</h1><p>If you are reading this, node-sendgrid somehow send you an email when it should've broke.</p>"
+ }, function (err) {
+ test.equal(err.name, "Error");
+ test.done();
+ });
+}

0 comments on commit 4e6e648

Please sign in to comment.