我想设置为我的灰烬CLI与Ember CLI Mirage(1.13.1)验收测试模拟服务器。我被困在如何调试设置并实际测试视图中可用的模型数据。调试灰烬CLI Mirage在验收测试
我尝试添加我的海市蜃楼路线内的控制台日志声明:
this.get('/users', function(db){
console.log(db.users);
return db.users;
});
告诉我,海市蜃楼路线被调用,应该有三个用户存在。但我的测试仍然失败。如何查看我的验收测试或我的模板中的商店内容?
测试/接受/用户/索引test.js
/* jshint expr:true */
import {
describe,
it,
beforeEach,
afterEach
} from 'mocha';
import { expect } from 'chai';
import Ember from 'ember';
import startApp from 'tagged/tests/helpers/start-app';
describe('Acceptance: UsersIndex', function() {
var application;
var users;
beforeEach(function() {
application = startApp();
users = server.createList('user', 3);
});
afterEach(function() {
Ember.run(application, 'destroy');
});
it('can visit /users/index', function() {
visit('/users');
andThen(function() {
expect(currentPath()).to.equal('users.index');
});
});
it('lists the users', function(){
visit('/users');
andThen(function() {
users = server.createList('user', 3);
expect(find('.user').length).to.equal(3); // fails
});
});
});
AssertionError: expected 0 to equal 3
应用程序/幻影/ config.js
export default function() {
/*
Config (with defaults).
Note: these only affect routes defined *after* them!
*/
this.namespace = '/api/v1'; // make this `api`, for example, if your API is namespaced
// this.timing = 400; // delay for each request, automatically set to 0 during testing
this.get('/users');
}
// You can optionally export a config that is only loaded during tests
export function testConfig() {
this.timing = 1;
}
应用程序/幻影/工厂/ user.js
import Mirage, {faker} from 'ember-cli-mirage';
export default Mirage.Factory.extend({
email: function(){ return faker.internet.email(); }
});
应用程序/路由/用户/ index.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function(){
return this.store.findAll('user');
}
});
应用/模板/用户/ index.hbs
<h2>Users</h2>
<table>
<thead>
<tr>
<th>Actions</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{{#each model as |user|}}
<tr class="user">
<td class="actions"><a href="#">Show</a></td>
<td class="email">{{ user.email }}</td>
</tr>
{{/each}}
</tbody>
</table>
是的,我正在使用'JSONAPIAdapter'。因为我以前使用过Sinon.fakeServer并根据JSONAPI设置了响应,所以很有意义。 – max
感谢您的快速响应! – max
所以我需要把工厂记录,并通过像[JSONAPISerializer](http://emberjs.com/api/data/classes/DS.JSONAPISerializer.html)? – max