1
嘿,我從來沒有用過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 }); }); });
它總是那些小事情,謝謝! –