पर लिखा था मैं तो बस जब आप "/" मार्ग का उपयोग कर ember.js मारा है कि एक साधारण संक्रमण करता है एक उदाहरण के आवेदन को धक्का दिया RC5
https://github.com/toranb/ember-testing-example
सरल "हैलो दुनिया" उदाहरण के इस
1. तरह दिखता है) ते आप संक्रमण
<table>
{{#each person in controller}}
<tr>
<td class="name">{{person.fullName}}</td>
<td><input type="submit" class="delete" value="delete" {{action deletePerson person}} /></td>
</tr>
{{/each}}
</table>
2.) ember.js आवेदन कोड
App = Ember.Application.create();
App.Router.map(function() {
this.resource("other", { path: "/" });
this.resource("people", { path: "/people" });
});
App.OtherRoute = Ember.Route.extend({
redirect: function() {
this.transitionTo('people');
}
});
App.PeopleRoute = Ember.Route.extend({
model: function() {
return App.Person.find();
}
});
App.Person = Ember.Object.extend({
firstName: '',
lastName: ''
});
App.Person.reopenClass({
people: [],
find: function() {
var self = this;
$.getJSON('/api/people', function(response) {
response.forEach(function(hash) {
var person = App.Person.create(hash);
Ember.run(self.people, self.people.pushObject, person);
});
}, this);
return this.people;
}
});
3.) एकीकरण परीक्षण इस
module('integration tests', {
setup: function() {
App.reset();
App.Person.people = [];
},
teardown: function() {
$.mockjaxClear();
}
});
test('ajax response with 2 people yields table with 2 rows', function() {
var json = [{firstName: "x", lastName: "y"}, {firstName: "h", lastName: "z"}];
stubEndpointForHttpRequest('/api/people', json);
visit("/").then(function() {
var rows = find("table tr").length;
equal(rows, 2, rows);
});
});
4.) की तरह दिखता है के दौरान करने के लिए रीडायरेक्ट mplate एकीकरण सहायक मैं अपने अधिकांश ember.js परियोजनाओं पर उपयोग करता हूं
document.write('<div id="foo"><div id="ember-testing"></div></div>');
Ember.testing = true;
App.rootElement = '#ember-testing';
App.setupForTesting();
App.injectTestHelpers();
function exists(selector) {
return !!find(selector).length;
}
function stubEndpointForHttpRequest(url, json) {
$.mockjax({
url: url,
dataType: 'json',
responseText: json
});
}
$.mockjaxSettings.logging = false;
$.mockjaxSettings.responseTime = 0;
आप एम्बर का किस संस्करण का उपयोग कर रहे हैं? मैं आरसी 6 में एक महत्वपूर्ण बग का उल्लेख करने में असफल रहा जो कि "/" मार्ग पर जाने पर टूट जाता है https://github.com/emberjs/ember.js/issues/2997 –
आह! मैं आर 6.1 का उपयोग कर रहा हूँ! क्षमा करें, मैं अपने प्रश्न में उल्लेख करना भूल गया। आपकी मदद के लिए बहुत धन्यवाद! – ganicus