我正在重写一个使用ember-cli的ember项目。由于Mocha的describeModel
函数带来了商店但describeModule
没有,我有点不能重写序列化器测试。
import { expect, assert } from 'chai';
import { describeModel,it } from 'ember-mocha';
describeModel('connection','Connection Desc', { needs: ['model:result'] },
function() {
it('exists', function() {
var model = this.subject();
var store = this.store();
expect(model).to.be.ok;
});
});
作为一种解决方法,我手动创建了一个商店,但我猜这不是很方便,并且确信有一种更易读的方法:
import App from '../../../app';
import { expect, assert } from 'chai';
import { describeModule, it } from 'ember-mocha';
describeModule( 'serializer:result', 'Result Serializer', { needs: ['model:result'] },
function() {
it('converts a single item on a result to a one element array', function(){
var serializer = this.subject();
App.ApplicationStore = DS.Store.extend({
adapter: DS.MochaAdapter
});
var store = App.ApplicationStore.create({
container: this.container
});
expect(
serializer.extractArray( store, store.modelFor('result'), {"results":[]})
).to.be.an.instanceOf(Array).and.have.lengthOf(0);
});
it("changes the recycle mode properly.", function () {
Mediator.ApplicationStore = DS.Store.extend({
adapter: DS.MochaAdapter
});
var store = Mediator.ApplicationStore.create({
container: this.container
});
var model = store.createRecord('result', {});
// ...
});
});
存在the possibility to mock,但是模仿商店的每一种可能的方法听起来并不诱人。
上面的示例是否有更短的方式获取DS.Store
实例(类似于subject
)?