Skip to content

Commit fbcceb8

Browse files
committedNov 11, 2013
Improve tests
1 parent 0e6f5bc commit fbcceb8

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed
 

‎test.js

+42-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require('./');
77

88
var tmpdir = path.join(__dirname, 'tmp', 'nodemailer');
99
var transport = nodemailer.createTransport('MailPreview', {
10-
dir: tmpdir,
10+
dir: tmpdir,
1111
browser: false
1212
});
1313

@@ -36,10 +36,49 @@ var email = {
3636

3737
describe('MailPreview', function(){
3838

39-
it('should add itself to nodemailer\'s transports', function(){
39+
it('adds itself to nodemailer\'s transports', function(){
4040
assert(nodemailer.Transport.transports.MAILPREVIEW);
4141
});
4242

43-
// TODO
43+
describe('.sendMail()', function(){
44+
var error, response;
4445

46+
before(function(done){
47+
transport.sendMail(email, function(e, r){
48+
error = e;
49+
response = r;
50+
done();
51+
});
52+
});
53+
54+
after(function(){
55+
try {
56+
// Cleanup files
57+
fs.unlinkSync(response.html);
58+
fs.unlinkSync(response.text);
59+
fs.rmdirSync(path.dirname(response.html));
60+
} catch (e) {
61+
console.error('Could not clean up temporary files');
62+
console.error(e.stack || e);
63+
}
64+
});
65+
66+
it('does not return an error', function(){
67+
assert(error == null);
68+
});
69+
70+
it('returns the details in the response', function(){
71+
assert(response.html && response.text);
72+
});
73+
74+
it('writes the text part of the email to the corresponding file', function(){
75+
var body = fs.readFileSync(response.text, 'utf-8');
76+
assert(body.indexOf("Hey jude, don't make it bad.") >= 0);
77+
});
78+
79+
it('writes the html part of the email to the corresponding file', function(){
80+
var body = fs.readFileSync(response.html, 'utf-8');
81+
assert(body.indexOf("<h1>Hey Jude</h1>") >= 0);
82+
});
83+
});
4584
});

0 commit comments

Comments
 (0)
Please sign in to comment.