為了測試用戶與應(yīng)用程序和應(yīng)用程序的交互,使用了驗收測試。通過使用驗收測試,用戶可以通過登錄表單登錄,并可以創(chuàng)建博客帖子。
<!DOCTYPE html> <html> <head> <title>Emberjs Acceptance Test</title> <!-- CDN's--> <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.1/handlebars.min.js"></script> <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <script src="https://builds.emberjs.com/tags/v1.10.0-beta.3/ember-template-compiler.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.10.0/ember.prod.js"></script> <script src="https://builds.emberjs.com/release/ember.debug.js"></script> <script src="https://builds.emberjs.com/beta/ember-data.js"></script> </head> <body> <div id="qunit"></div> <div id="ember-testing-container"><div id="ember-testing"></div></div> <script type="text/x-handlebars" data-template-name="index"> <h2>Names are:</h2> <ul> {{#each}} <li>{{#link-to 'post' this}} {{firstName}} {{lastName}} {{/link-to}}</li> {{/each}} </ul> </script> <script type="text/x-handlebars" data-template-name="post"> <h2>Name :</h2> <p id='name'> {{firstName}} </p> </script> <script type="text/javascript"> //Creates an instance of Ember.Application and assign it to a global variable App = Ember.Application.create(); //The store cache of all records available in an application App.Store = DS.Store.extend({ //adapter translating requested records into the appropriate calls adapter: DS.FixtureAdapter }); App.Router.map(function() { //post route this.route('post', { path: ':person_id' }); }); App.IndexRoute = Ember.Route.extend({ model: function() { return this.store.find('person'); } }); App.Person = DS.Model.extend({ //setting firstName and lastName attributes as string firstName: DS.attr('string'), lastName: DS.attr('string') }); //attach fixtures(sample data) to the model's class App.Person.FIXTURES = [ {id: 1, firstName: 'John', lastName: 'Smith'}, {id: 2, firstName: 'Tom', lastName: 'Cruise'}, {id: 3, firstName: 'Shane', lastName: 'Watson'} ]; App.rootElement = '#ember-testing'; //Ember.js applications's root element //These two methods to prepare the application for testing App.setupForTesting(); App.injectTestHelpers(); module("Emberjs", { setup: function() { Ember.run(App, App.advanceReadiness); //'advanceReadiness' runs the application when not under test }, //This function is called for each test in the module teardown: function() { App.reset(); //After each test, reset the state of the application } }); //Here, it tests the workflow of application test("Check HTML is returned", function() { visit("/").then(function() { ok(exists("*"), "Found HTML!"); }); }); </script> </body> </html>
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將上面的代碼保存在testing_acceptance_test.html文件中
在瀏覽器中打開此HTML文件。
更多建議: