KeystoneJS Markdown Type Passing Validation when empty

时间:2015-09-01 21:21:29

标签: keystonejs

Background:

I have a field of type Markdown. When I try unit testing it, the value initializes to what's seen below -- which passes validation.

{
  "html": [undefined]
  "md": [undefined]
  "toJSON": [Function]
  "toObject": [Function]
}

The model is as follows:

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;

and the 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();
    });
  });
});

When running as is, the save passes with no error, so it doesn't hit done and times out. Switching the type to flat field types such as Text, Html, Boolean, Color, Date, Datetime, or Key will work as expected(ValidationError). I get the same issue if I switch the type to be another embedded type such as Name or Location.

Questions:

  1. Is this the expected behavior?
  2. If so, how can I modify my testing approach?

1 个答案:

答案 0 :(得分:0)

这绝对不是预期的行为。但我们可能没有测试过这个边缘。请在项目上打开一个问题。 https://github.com/keystonejs/keystone