我正在尝试使用 Ember Validations 插件,但无法正常工作。在 Chrome 控制台中,我看到:警告:找不到“存在”验证器。
这是我的模型:
import Ember from 'ember';
import DS from 'ember-data';
import EmberValidations from 'ember-validations';
export default DS.Model.extend(EmberValidations.Mixin, {
name: DS.attr('string'),
validations: {
name: {
presence: true
}
}
});
这是我的测试:
import Ember from 'ember';
import EmberValidations from 'ember-validations';
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('person', 'Unit | Model | person', {
// Specify the other units that are required for this test.
needs: ['ember-validations@validator:local/presence'],
afterEach: function() {
window.sessionStorage.clear();
}
});
test('isValid should be false if name is not set', function(assert) {
stop();
var model = this.subject();
console.log(model);
Ember.run(function() {
sinon.spy(model, 'save');
model.validate().then(function() {
start();
assert.equal(model.get('isValid'), false);
});
});
});
这个测试的结果是:
在http://localhost:4200/assets/myproj.js:14450:15 在 mod的 Object.test ( http://localhost:4200/assets/test-support.js:1644:11 ) 的测试 #1 .state ( http://localhost:4200/assets/vendor.js:150:29 ) at tryFinally ( http://localhost:4200/assets/vendor.js:30:14 ) at requireModule ( http://localhost :4200/assets/vendor.js:148:5 ) 在 Object.TestLoader.require ( http://localhost:4200/assets/test-loader.js:29:9 ) 在 Object.TestLoader.loadModules ( http:// /localhost:4200/assets/test-loader.js:21:18 ): <(unknown mixin):ember848>