adopted-ember-addons / adopted-ember-addons/ember-cp-validations

error calling model.validate from Unit test (solved by including validator:ds-error in "needs")

未关闭
#555 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
439
派生
172
PR 合并指标
30 天内没有已合并 PR

描述

First, thanks for all the great packages :)

When trying to write a unit test for the validation of an ember-model, I stumbled onto getting this error:

Died on test #1 at Anonymous function (http://localhost:7357/assets/tests.js:3207:4)
at Module.prototype.exports (http://localhost:7357/assets/vendor.js:92:7)
at Module.prototype.build (http://localhost:7357/assets/vendor.js:142:5)
at findModule (http://localhost:7357/assets/vendor.js:190:5)
at requireModule (http://localhost:7357/assets/vendor.js:177:5)
at TestLoader.prototype.require (http://localhost:7357/assets/test-loader.js:67:9)
at TestLoader.prototype.loadModules (http://localhost:7357/assets/test-loader.js:58:13): Assertion Failed: Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container.

The error is correct, but not very helpfull in finding the problem, which turns out is that i need to include:
'validator:ds-error' in my needs clause (see test code below).

I am aware that this is not a bug perse, but maybe it can be documented somewhere (better) ?
Or maybe the error could be more descriptive...

### Environment
- Ember Version: 2.4.5
- Ember CLI Version: 2.5.0
- Ember CP Validations Version: 2.9.8

### Steps to Reproduce - Unit test:
```
import { moduleForModel, test } from 'ember-qunit';

moduleForModel('recipient', 'Unit | Model | recipient', {
// Specify the other units that are required for this test.
needs: [
'validator:ds-error', // this two lines are needed - without it calling validate gives an error !!!
'validator:messages',
'validator:presence',
'validator:length',
'validator:number',
'validator:belongs-to',
'validator:has-many'
]
});

test('it exists', function(assert) {
let model = this.subject();
assert.ok(!!model);
});

test('it can validate', function(assert) {
let model = this.subject();
model.validate();
assert.ok(true);
});
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。