From af680e4f23579908881e172cadb27ee0c9d52c82 Mon Sep 17 00:00:00 2001 From: Trevin Hofmann Date: Sun, 8 Feb 2015 03:16:18 -0600 Subject: [PATCH] Add some tests for new methods It should now test `toJSON`, `fromJSON`, `toString`, `fromString`, and `inspect`. --- test/message.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/message.js b/test/message.js index c37e5d2..9e00cc0 100644 --- a/test/message.js +++ b/test/message.js @@ -104,4 +104,47 @@ describe('Message', function() { verified.should.equal(true); }); + describe('#json', function() { + + it('roundtrip to-from-to', function() { + var json = new Message(text).toJSON(); + var message = Message.fromJSON(json); + message.toString().should.equal(message); + }); + + it('checks that the string parameter is valid JSON', function() { + expect(function() { + return Message.fromJSON('ยน'); + }).to.throw(); + }); + + }); + + describe('#toString', function() { + + it('message string', function() { + var message = new Message(text); + message.toString().should.equal(text); + }); + + it('roundtrip to-from-to', function() { + var str = new Message(text).toString(); + var message = Message.fromString(str); + message.toString().should.equal(message); + }); + + }); + + describe('#inspect', function() { + + it('should output formatted output correctly', function() { + var message = new Message(text); + var output = ''; + message.inspect().should.equal(output); + }); + + }); + + + });