'qunit' is not recognised as an internal or external command, operable program or batch file

南楼画角 提交于 2019-12-12 01:29:17

问题


I installed qunit, using command:

npm install -g qunit

Then, I wrote a test program and named the file as firstTest.js. The contents of firstTest.js is:

module.exports = {  
    'should run test': function(t) {  
        t.printf("running test!\n");  
        t.done();  
    },  
};  

On executing command:

qunit firstTest.js

I got 'qunit' is not recognised as an internal or external command, operable program or batch file. What should I do ?


回答1:


Okay, so first off, that is not how you write a QUnit test. You can read the documentation here, but essentially you need to write code that a browser can interpret, and module.exports is not a browser object, it's only in Node.

Now, if you are using some other Node module that let's you write tests that way, cool! But if you are using the base qunit module you can't write tests that way. Here's how you can write that test in proper QUnit:

QUnit.test("should run test", function( assert ) {
  console.log("running test!");
  assert.ok(1 === 1, "one equal one");
});

Now you need to load that test file in an HTML file and open it in the browser:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>QUnit Example</title>
  <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.1.1.css">
</head>
<body>
  <div id="qunit"></div>
  <script src="https://code.jquery.com/qunit/qunit-2.1.1.js"></script>
  <script src="test.js"></script>
</body>
</html>

Second, QUnit does not have a CLI executable program bundled with it. You will need to use another module to run that test from the command line. Something like the task runner Grunt combined with the grunt-contrib-qunit plugin.



来源:https://stackoverflow.com/questions/41802224/qunit-is-not-recognised-as-an-internal-or-external-command-operable-program-o

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