dimanche 31 juillet 2016

QUnit not running external JavaScript file

I'm trying to adapt the tutorial here to use QUnit v2.x, but it doesn't seem to be picking up the JavaScript file I want to test.

test.html

<script src="http://ift.tt/wV40hO"></script>
<script src="qunit.js"></script>
<script src="../list.js"></script>
<script>

    QUnit.test("errors should be hidden on keypress", function (assert) {
        $('input').trigger('keypress');
        assert.equal($('.has-error').is(':visible'), false);
    });

</script>

list.js

jQuery(document).ready(function ($) {
    $('input').on('keypress', function () {
        $('.has-error').hide();
    });
});

The test fails with a result of true

The provided code in the tutorial works fine with QUnit 1.8

<script>

/*global $, test, equal */

test("errors should be hidden on keypress", function () {
    $('input').trigger('keypress');
    equal($('.has-error').is(':visible'), false);
});

test("errors not be hidden unless there is a keypress", function () {
    equal($('.has-error').is(':visible'), true);
});

</script>

Aucun commentaire:

Enregistrer un commentaire