Files
zulip/frontend_tests/node_tests/schema.js
Anders Kaseorg 6ec808b8df js: Add "use strict" directive to CommonJS files.
ES and TypeScript modules are strict by default and don’t need this
directive.  ESLint will remind us to add it to new CommonJS files and
remove it from ES and TypeScript modules.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 22:09:46 -07:00

34 lines
1.0 KiB
JavaScript

"use strict";
zrequire("schema");
run_test("basics", () => {
assert.equal(schema.check_string("x", "fred"), undefined);
assert.equal(schema.check_string("x", [1, 2]), "x is not a string");
const fields = {
foo: schema.check_string,
bar: schema.check_string,
};
const check_rec = (val) => schema.check_record("my_rec", val, fields);
assert.equal(check_rec({foo: "apple", bar: "banana"}), undefined);
assert.equal(check_rec("bogus"), "my_rec is not a record");
assert.equal(check_rec({foo: "apple"}), "in my_rec bar is missing");
assert.equal(check_rec({}), "in my_rec bar is missing, foo is missing");
assert.equal(check_rec({foo: "apple", bar: 42}), "in my_rec bar is not a string");
const check_array = (val) => schema.check_array("lst", val, schema.check_string);
assert.equal(check_array(["foo", "bar"]), undefined);
assert.equal(check_array("foo"), "lst is not an array");
assert.equal(check_array(["foo", 3]), "in lst we found an item where item is not a string");
});