jQuery validator not working in unit testing

Posted by Dbugger on Stack Overflow See other posts from Stack Overflow or by Dbugger
Published on 2013-06-24T16:17:08Z Indexed on 2013/06/24 16:21 UTC
Read the original article Hit count: 476

Filed under:
|
|

I have this small HTML file:

<html>
    <head></head>
    <body>
        <form id='MyForm'>
            <input type='text' required />
            <input type='submit' />
        </form>

        <script src="/js/jquery-1.9.0.js"></script>
        <script src="/js/jquery.validate.js"></script>
        <script>
            var validator = $("#MyForm").validate();
            alert(validator.form());
        </script>
    </body>
</html>

This alerts me with "false", which is the expected behaviour.

The problem comes when I go to unit testing, with js-test-driver:

TestCase("MyTests", {

    setUp: function() {
        this.myform = "<form id='MyForm'><input type='text' required /><input type='submit'  /></form>";

        this.validator = $(this.myform).validate();
        jstestdriver.console.log("Does the form validate? " + this.validator.form());
    },

    test_empty: function() {
    },

});

This code returns me the string

Does the form validate? true

This is a simplified version of my project of course, but the point is that I dont seem to be able to unit test the validation module im developing, since the jQuery validate plugin doesnt seem to work. What am I missing?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about unit-testing