0
我实际上已经在simple-schema Github问题上发布了这个w/no response。我的代码可能是错误的,或者我对JS OOP的理解可能是错误的,因为我来自Java和PHP背景。所以,我不知道这是否是一个错误,但似乎:对一个类的空实例进行流星简单模式验证
check({}, Schema.User)
会引发一个例外,因为空对象缺少所需的字段,但check(new User(), Schema.User)
将是有效的
不new User()
咋办也没有必填字段的值?
这里也是一个快速的实验我做:
it("does not validate correctly if i give it an instance", function() {
var Bee, b, schema;
schema = new SimpleSchema({
name: {
type: String,
optional: false
}
});
Bee = function() {};
b = new Bee();
schema.newContext().validate(b, {modifier: false}).should.be.false // validate is true here
});
it("works if i give it {}", function() {
var schema;
schema = new SimpleSchema({
name: {
type: String,
optional: false
}
});
schema.newContext().validate({}, {modifier: false}).should.be.false // validate is false here
});