protobuf.js/tests/api_Class.js

37 lines
1.2 KiB
JavaScript

var tape = require("tape");
var protobuf = require("..");
var proto = "message Something {}";
tape.test("classes", function(test) {
var root = protobuf.parse(proto).root,
Something = root.lookup("Something");
test.throws(function() {
new protobuf.Class("a");
}, TypeError, "new Class should throw if first argument is not a Type");
test.throws(function() {
protobuf.Class.create("a");
}, TypeError, "Class.create should throw if first argument is not a Type");
test.throws(function() {
protobuf.Class.create(Something, "a");
}, TypeError, "Class.create should throw if second argument is not a function");
test.test("should construct equally using Class.create or new Class", function(test) {
var proto1 = new protobuf.Class(Something),
proto2 = protobuf.Class.create(Something);
for (var key in proto1) {
if (typeof proto1[key] === "function")
test.equal(proto1[key].toString(), proto2[key].toString(), "with the same " + key + " function");
else
test.same(proto1[key], proto2[key], "with the same " + key + " value");
}
test.end();
});
test.end();
});