我想設置爲我的灰燼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