【发布时间】:2017-09-25 06:40:05
【问题描述】:
我以前从未使用过 Jasmine,但我正在从事的这个小项目需要我。不太清楚,任何帮助将不胜感激。我查看了各种教程并用谷歌搜索了这个问题,但对这个问题很陌生。
JS源文件
> $(document).ready(function(){
>
>
> $.ajax({ type: 'GET', dataType: "json", url: "db.php/realmadrids",
> success: showResponse, error: showError });
>
>
>
>
>
>
> console.debug("error"); function showResponse(responseData){
>
> //$("#get1").click(function getPlayers(responseData) {
> console.log('Image is clicked'); console.log(responseData);
> $.each(responseData.realmadrid, function(index, realmadrid){
> console.log(' is ');
> $("#playercontentRealMadrid").append("</br><strong> Full Name: </strong>" +realmadrid.PlayerName+ " "+realmadrid.PlayerLastName+"
> </br> <strong>Player Position: </strong>" +realmadrid.PlayerPosition+"
> </br><strong>Player Age: </strong>" +realmadrid.Age+"
> </br><strong>Player Height: </strong>" +realmadrid.Height+"
> </br><strong>Player Weight: </strong>" +realmadrid.Weight+"
> </br><strong>Team Name: </strong>" +realmadrid.TeamName+"</br>");
>
> console.log('Data should output'); // }); });
>
> console.log(responseData);
> }
> console.debug("hello");
>
> function showError(){ alert("Sorry, but something went wrong. Fix
> it!!!!") }
>
> });
这是我的测试代码:
//Test Suite describe("Spy on my own AJAX call", function(){ it("should make AJAX request with successful setting", function() { spyOn($, "ajax"); expect($.ajax).toHaveBeenCalledWith({ url:'db.php/realmadrids', type:'GET', dataType: "json", sucess: showResponse, error: showError }); }); });
【问题讨论】:
标签: javascript jquery ajax unit-testing jasmine