UNPKG

@schukai/monster

Version:

Monster is a simple library for creating fast, robust and lightweight websites.

50 lines (40 loc) 1.24 kB
import {expect} from "chai" import {Message} from "../../../../source/net/webconnect/message.mjs"; describe('Message', function () { it('construct withouth parameters should throw', function (done) { try { new Message(); done(new Error('should throw')); } catch (e) { done(); } }) it('from json should ' , function (done) { const json = { "id": "123", "type": "test", "data": { "test": "test" } } const message = Message.fromJSON(JSON.stringify(json)); const data = message.getData(); expect(data.id).to.equal(json.id); expect(data.type).to.equal(json.type); expect(data.data).to.deep.equal(json.data); done(); }) it ("to json should", function (done) { const obj = { "id": "123", "type": "test", "data": { "test": "test" } } const message = new Message(obj); const data = JSON.stringify(message); expect(data).to.equal('{"id":"123","type":"test","data":{"test":"test"}}'); done(); }) });