Skip to content

Commit

Permalink
Default value and adds required (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Aug 24, 2018
1 parent 182970c commit 139cda5
Showing 1 changed file with 53 additions and 35 deletions.
88 changes: 53 additions & 35 deletions test/serial/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,64 @@ describe("serial/property", function () {

describe("_gpfSerialPropertyCheck", function () {

it("validates name", function () {
var exceptionCaught;
try {
_gpfSerialPropertyCheck({
name: "OK"
});
} catch (e) {
exceptionCaught = e;
}
assert(!exceptionCaught);
it("validates name and default properties", function () {
var property = _gpfSerialPropertyCheck({
name: "OK"
});
assert(property.type === gpf.serial.types.string);
assert(property.required === false);
});

[undefined].concat(values).forEach(function (invalidName) {
it("rejects invalid names (" + JSON.stringify(invalidName) + ")", function () {
var exceptionCaught;
try {
_gpfSerialPropertyCheck({
name: invalidName
});
} catch (e) {
exceptionCaught = e;
}
assert(exceptionCaught instanceof gpf.Error.InvalidSerialName);
values
.concat(undefined)
.forEach(function (invalidName) {
it("rejects invalid 'name' (" + JSON.stringify(invalidName) + ")", function () {
var exceptionCaught;
try {
_gpfSerialPropertyCheck({
name: invalidName
});
} catch (e) {
exceptionCaught = e;
}
assert(exceptionCaught instanceof gpf.Error.InvalidSerialName);
});
});
});

values.forEach(function (invalidType) {
it("rejects invalid types (" + JSON.stringify(invalidType) + ")", function () {
var exceptionCaught;
try {
_gpfSerialPropertyCheck({
name: "OK",
type: invalidType
});
} catch (e) {
exceptionCaught = e;
}
assert(exceptionCaught instanceof gpf.Error.InvalidSerialType);
values
.forEach(function (invalidType) {
it("rejects invalid 'type' (" + JSON.stringify(invalidType) + ")", function () {
var exceptionCaught;
try {
_gpfSerialPropertyCheck({
name: "OK",
type: invalidType
});
} catch (e) {
exceptionCaught = e;
}
assert(exceptionCaught instanceof gpf.Error.InvalidSerialType);
});
});

values
.filter(function (value) {
return "boolean" !== typeof value;
})
.forEach(function (invalidRequired) {
it("rejects invalid 'required' (" + JSON.stringify(invalidRequired) + ")", function () {
var exceptionCaught;
try {
_gpfSerialPropertyCheck({
name: "OK",
required: invalidRequired
});
} catch (e) {
exceptionCaught = e;
}
assert(exceptionCaught instanceof gpf.Error.InvalidSerialRequired);
});
});
});

});

Expand Down

0 comments on commit 139cda5

Please sign in to comment.