2014-05-15 7 views
5

Le fixture funzionano bene per le mie suite di test in jasmine.js versione 1.3.1. Dopo aver aggiornato la versione di Jasmine.js alla versione 2.0.0, i dispositivi non funzionano.Come utilizzare i dispositivi in ​​Jasmine.js versione 2.0.0?

Qualcuno può spiegare come rendere il mio codice utilizzabile per i dispositivi in ​​jasmine.js versione 2.0.0?

ho controllato questo gelsomino V2.0.0 note di rilascio, ma niente releated alle lampade: https://github.com/pivotal/jasmine/blob/v2.0.0/release_notes/20.md

Grazie.

risposta

4

Lo script completo di seguito sta funzionando correttamente per me per caricare i proiettori per testare i frammenti di codice HTML.

ho accennato questo URL e questo URL mi ha aiutato a caricare gli infissi: http://www.htmlgoodies.com/beyond/javascript/js-ref/testing-dom-events-using-jquery-and-jasmine-2.0.html

e devi controllo alcuni dei sintassi quadro Jasmine.js così in jasmine.js v2.0.0

<!DOCTYPE HTML> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>Jasmine v2.0 DOM Tests Spec Runner</title> 

    <link rel="shortcut icon" type="image/png" href="images/jasmine_favicon.png"> 
    <link rel="stylesheet" type="text/css" href="lib/jasmine-core/jasmine.css"> 

    <script type="text/javascript" src="lib/jasmine-core/jasmine.js"></script> 
    <script type="text/javascript" src="lib/jasmine-core/jasmine-html.js"></script> 
    <script type="text/javascript" src="lib/jasmine-core/boot.js"></script> 
    <script type="text/javascript" src="lib/jasmine-core/jquery-1.7.2.js"></script> 
    <script type="text/javascript" src="lib/jasmine-core/jasmine-jquery.js"></script> 

    <script type="text/javascript"> 
    var MSG = "Hello World!"; 

    function hideMessage() { 
     $("#pMsg").html(""); 
    } 

    function showMessage() { 
     $("#pMsg").html(MSG); 
    } 

    function setUpHTMLFixture() { 
     setFixtures('<form id="testForm" action="">' 
        +' <h1>Test Form</h1>' 
        +' <input type="text" id="txtMessage">' 
        +' <br>' 
        +' <button id="btnHideMessage" type="button" onclick="hideMessage()">Hide Message</button>' 
        +' <button id="btnShowMessage" type="button" onclick="showMessage()">Show Message</button>' 
        +' <br>' 
        +' <p id="pMsg"></p>' 
        +'</form>'); 

    } 

describe("DOM TESTS:***************", function() { 
    describe("Button Click Event Tests", function() { 
    var spyEvent; 

    beforeEach(function() { 
     setUpHTMLFixture(); 
    }); 

    it ("should invoke the btnShowMessage click event.", function() { 
     spyEvent = spyOnEvent('#btnShowMessage', 'click'); 
     $('#btnShowMessage').trigger("click"); 

     expect('click').toHaveBeenTriggeredOn('#btnShowMessage'); 
     expect(spyEvent).toHaveBeenTriggered(); 
    }); 

    it ("should invoke the btnHideMessage click event.", function() { 
     spyEvent = spyOnEvent('#btnHideMessage', 'click'); 
     $('#btnHideMessage').trigger("click"); 

     expect('click').toHaveBeenTriggeredOn('#btnHideMessage'); 
     expect(spyEvent).toHaveBeenTriggered(); 
    }); 
    }); 

    describe("Show message tests", function() { 
    beforeEach(function() { 
     setUpHTMLFixture(); 
     $('#txtMessage').val(MSG); 
     $('#btnShowMessage').trigger("click"); 
    }); 

    it ("should display the message when button is clicked.", function() { 
     expect($('#pMsg')).toHaveText($('#txtMessage').val()); 
    }); 
    }); 

    describe("Hide message tests", function() { 
    beforeEach(function() { 
     setUpHTMLFixture(); 
     $('#pMsg').text(MSG); 
     $('#btnHideMessage').trigger("click"); 
    }); 

    it ("should remove the message when button is clicked.", function() { 
     expect($('#pMsg')).toHaveText(""); 
    }); 
    }); 
}); 
</script> 
</head> 
<body> 
</body> 
</html> 
+0

Grazie, è un lavoro per me. – KumarA

Problemi correlati