KeystoneJS Markdown 类型在为空时通过验证
KeystoneJS Markdown Type Passing Validation when empty
背景:
我有一个 Markdown 类型的字段。当我尝试对其进行单元测试时,该值初始化为如下所示 - 通过了验证。
{
"html": [undefined]
"md": [undefined]
"toJSON": [Function]
"toObject": [Function]
}
模型如下:
var keystone = require('keystone');
var Types = keystone.Field.Types;
/**
* Test Model
* ==========
*/
var Test = new keystone.List('Test');
Test.add({
name: {type: Types.Name, required: true, initial: true, index: true},
otherField: {type: Types.Markdown, initial: true, required: true},
});
/**
* Registration
*/
Test.defaultColumns = 'name, otherField';
Test.register();
module.exports = Test;
和测试:
var expect = require('chai').expect;
var keystone = require('keystone');
describe('Test', function() {
keystone.init({name: 'Test Example'});
keystone.import('../../models');
var Test;
it('should should fail validation when otherField is empty',function(done) {
Test = keystone.list('Test');
var test = new Test.model();
test.name.full = 'Jane Doe';
test.save(function(err) {
expect(err.name).to.equal('ValidationError');
done();
});
});
});
当 运行 按原样保存时,保存没有错误地通过,因此它不会完成并超时。将类型切换为文本、Html、布尔值、颜色、日期、日期时间或键等平面字段类型将按预期工作(ValidationError)。如果我将类型切换为另一种嵌入类型(例如名称或位置),我会遇到同样的问题。
问题:
- 这是预期的行为吗?
- 如果是这样,我该如何修改我的测试方法?
这肯定不是预期的行为。但是我们可能没有测试过这个边缘情况。请在项目上打开一个问题。 https://github.com/keystonejs/keystone
背景:
我有一个 Markdown 类型的字段。当我尝试对其进行单元测试时,该值初始化为如下所示 - 通过了验证。
{
"html": [undefined]
"md": [undefined]
"toJSON": [Function]
"toObject": [Function]
}
模型如下:
var keystone = require('keystone');
var Types = keystone.Field.Types;
/**
* Test Model
* ==========
*/
var Test = new keystone.List('Test');
Test.add({
name: {type: Types.Name, required: true, initial: true, index: true},
otherField: {type: Types.Markdown, initial: true, required: true},
});
/**
* Registration
*/
Test.defaultColumns = 'name, otherField';
Test.register();
module.exports = Test;
和测试:
var expect = require('chai').expect;
var keystone = require('keystone');
describe('Test', function() {
keystone.init({name: 'Test Example'});
keystone.import('../../models');
var Test;
it('should should fail validation when otherField is empty',function(done) {
Test = keystone.list('Test');
var test = new Test.model();
test.name.full = 'Jane Doe';
test.save(function(err) {
expect(err.name).to.equal('ValidationError');
done();
});
});
});
当 运行 按原样保存时,保存没有错误地通过,因此它不会完成并超时。将类型切换为文本、Html、布尔值、颜色、日期、日期时间或键等平面字段类型将按预期工作(ValidationError)。如果我将类型切换为另一种嵌入类型(例如名称或位置),我会遇到同样的问题。
问题:
- 这是预期的行为吗?
- 如果是这样,我该如何修改我的测试方法?
这肯定不是预期的行为。但是我们可能没有测试过这个边缘情况。请在项目上打开一个问题。 https://github.com/keystonejs/keystone