Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed an SPA application using knockout and breeze, I have been using qunitJS for unit testing which works well on browser for my project. Recently I have found a plugin "Chutzpah" for VS2012, which can work well for testing qunit, which can check the test cases and respond for the Test though I am using breeze my test cases includes:

Creating, Deleting, Modifying entities on client side

Save changes on server side using breeze controller to SQLServer

Here the problem is the breeze test cases fails when I am testing in Chutzpah because they are not getting client side information like(Metadata/ ControllerMethods) which is called by the browser through the url defined in Breezeconfig. My question is that how can we perform unit test on breeze on server side like real unit test cases do. Suggestions for using new plugins or libraries which can actually make me do the unit testing of breeze are welcome

Here is the snippet for my testing project:

JavaScript
 asyncTest("can save nothing", function () {
  expect(1);
  newEm().saveChanges()
      .then(function(saveResult) {
          equal(saveResult.entities.length, 0, 'succeeded in saving nothing');
      })
      .catch(handleFail).finally(start);
});

asyncTest("can save a new Customer entity", function () {
  expect(1);

    // Create and initialize entity to save
    var em = newEm();
    var customer = em.createEntity('Customer', {
        CustomerID: newGuidComb(),
        CompanyName: 'Test1 ' + new Date().toISOString()
    });

    em.saveChanges()
        .then(function (saveResults) {
            ok(!!saveResults.entities[0], ' should have saved new Customer with CustomerID ' +
                customer.getProperty('CustomerID'));
        })
        .catch(handleFail).finally(start);
});

asyncTest("can modify my own Customer entity", function () {
    expect(2);
    var timestamp = new Date().toISOString();
    var em = newEm();

    var customer = em.createEntity('Customer', {
        CustomerID: newGuidComb(),
        CompanyName: "Test2A " + timestamp
    });

    em.saveChanges().then(modifyCustomer).fail(handleSaveFailed).fin(start);

    function modifyCustomer(saveResults) {
        var saved = saveResults.entities[0];
        ok(saved && saved === customer,
            "save of added customer should have succeeded");
        customer.CompanyName("Test2M " + timestamp);
        return em.saveChanges()
        .then(confirmCustomerSaved);
    }

    function confirmCustomerSaved(saveResults) {
        var saved = saveResults.entities[0];
        ok(saved && saved === customer,
            "save of modified customer, '{0}', should have succeeded"
            .format(saved && saved.CompanyName()));
    }

});
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900