can't browserify file - “Error: Parsing file” (HTML5 checkValidity() ?)

牧云@^-^@ 提交于 2020-01-25 08:35:12

问题


I want to see if I can test form field validation using mocha & chai.

I have the following files:

./src/index.html:

<!doctype html>
<html>
    <head>
        <title>TDD Project</title>
        <style>
            #container {width: 600px; max-width: 100%; margin: 1em auto;}
        </style>
        <link rel="stylesheet" href="../node_modules/mocha/mocha.css">
    </head>
    <body>
        <div id="container">
            <form>
                <input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
                <input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="\d{10}"><br />
                <input type="submit">
            </form>
        </div>
        <div id="mocha"></div>
        <script src="../node_modules/mocha/mocha.js"></script>
        <script src="../node_modules/chai/chai.js"></script>
        <script>mocha.setup('bdd')</script>

        <script src="../test/test2.js"></script>

        <script>
          mocha.run();
        </script>        
    </body>
</html>

./test/test.js:

var assert = require("chai").assert;

function FormController() {
    function isValidField(fieldID){
        field = document.getElementById(fieldID);
        return(field.checkValidity() = true ? true : false);
    }
    return {
        isValidField
    }
}

describe("Simple assert", function() {
    it("foo != bar", function() {
        assert('foo' != 'bar', 'foo is not bar');
    });
    it('should return true if field is valid', function(){
        var isValidText = FormController.isValidField(text);
        var isValidNumber = FormController.isValidField(number);
        assert.equal(isValidText, true);
        assert.equal(isValidNumber, true);
    });
})

I have run the commands > cd test

> browserify test.js > test2.js

I receive the error:

Error: Parsing file /Users/user/Documents/Projects/Contact_Form/test/test.js: Assigning to rvalue (6:15)

The problem appears to be with field.checkValidity() but I don't understand why.

Is it because the file test.js cannot access the DOM?

checkValidity() is a "HTML5 constraint validation API" discussed on this page.

Help appreciated.


回答1:


From this answer:

You get rvalue error, when you use = instead of == in a condition checking block.



来源:https://stackoverflow.com/questions/53385821/cant-browserify-file-error-parsing-file-html5-checkvalidity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!