问题
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