Jasmine ReferenceError: spyOnEvent не определен - PullRequest
0 голосов
/ 14 мая 2019

У меня есть страница, которая суммирует числовые входы из 2 полей ввода, и я пытаюсь выполнить модульный тест для слежки за событием нажатия кнопки с Жасмин, но Жасмин выбрасывает ReferenceError: spyOnEvent is not defined.

Я пытался включить jasmine-jquery, но это не сработало.

это страница:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Writing JavaScript test cases with Jasmine framework</title>
    <meta charset="utf-8" />
    <link href="Content/themes/base/jquery-ui.min.css" rel="stylesheet" />
    <link href="Content/themes/base/base.css" rel="stylesheet" />
    <script src="Scripts/jquery-3.4.1.min.js"></script>
    <script src="Scripts/jquery-ui-1.12.1.min.js"></script>
    <script src="test1.js"></script>
</head>
<body>
    <input type="number" id="firstVal"> + 
    <input type="number" id="secondVal"> = 
    <input type="number" id="result"><br>
    <input type="submit" id="submitRes">
</body>
</html>

это код JavaScript, который используется и тестируется (test1.js):

$(document).ready(function () {
    $("#submitRes").click(sumUp);    
});

function sumUp() {
    $('#result').val(+$('#firstVal').val() + +$('#secondVal').val());
}

это Жасмин СпецРаннер:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Jasmine Spec Runner</title>
    <link href="Content/jasmine/jasmine.css" rel="stylesheet" />
    <script src="http://localhost:57596/Scripts/jquery-3.4.1.min.js"></script>
    <script src="http://localhost:57596/Scripts/jquery-ui-1.12.1.min.js"></script>
    <script src="Scripts/jasmine/jasmine.js"></script>
    <script src="Scripts/jasmine/jasmine-html.js"></script>
    <script src="Scripts/jasmine/jasmine-jquery.js"></script>
    <script src="Scripts/jasmine/console.js"></script>
    <script src="Scripts/jasmine/boot.js"></script>
    <script src="Scripts/jquery/jquery-3.4.1.js"></script>
    <script src="Scripts/indextests.js"></script>
    <script src="http://localhost:57596/test1.js"></script>
</head>
<body>

</body>
</html>

это тестовый файл JavaScript indextests.js:

describe("Button Click Event tests: ", function () {
    var spyEvent;
    beforeEach(function () {
        sumUp();
    });
    it("spy on button", function () {
        spyEvent = spyOnEvent('#submitRes', 'click');
        $('#submitRes').trigger('click');

        expect('click').toHaveBeenTriggeredOn('#submitRes');
        expect(spyEvent).toHaveBeenTriggered();
    });
}); 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...