????karma???angular????runner????????????ù?karma???????????????javascript????runner????????????????karma.config.js?????karma init?Щ????????command???????????????????html2js??coverage??????angular???????karma???????????????????????????????????????????
?????????????????karma???jQuery???????runner??????jQuery????DOM???????????????????view????????ajax???????????mock????????????????jQuery?????TDD??????
????jasmime???????
????????jasmine?????????????Щ?????????????jasmine-jquery??jasmine-ajax??
????jasmine-jquery
????jasmine-jQuery??????????????????DOM????????????????????????jasmine-jQuery????DOM??????
????jasmine.getFixtures().fixturesPath = 'base path';
????loadFixtures('myfixture.html');
????jasmine.getFixtures().load(...);
?????????loadFixtures??????ajax???html fixtures??????????????host html fixtures??jasmine-jQuery????????Щ?????matchers????toBeChecked?? toBeDisabled?? toBeFocused??toBeInDOM……
????jasmine-ajax
????jasmine-ajax??????????ajax?????mock?????????xmlhttprequest??mock?????????????????????????jQuery??$.ajax??$.get…mock????
beforeEach(function() {
jasmine.Ajax.requests.when = function (url) {
return this.filter("/jquery/ajax")[0];
};
jasmine.Ajax.install();
});
it("jquery ajax success with getResponse"?? function() {
var result;
$.get("/jquery/ajax").success(function(data) {
result = data;
});
jasmine.Ajax.requests.when("/jquery/ajax").response({
"status": 200??
"contentType": 'text/plain'??
"responseText": 'data from mock ajax'
});
expect(result).toEqual('data from mock ajax');
});
afterEach(function() {
jasmine.Ajax.uninstall();
});
????????jasmine-ajax????mock????????jasmine.Ajax.install()????????????????jasmine.Ajax.uninstall();jasmine-ajax??install???????е?ajax mock??????????????????ajax???????install????????jasmine-jQuery????view loadFixtures??