'qunit' 不是内部或外部命令,也不是可运行的程序或批处理文件 [英] 'qunit' is not recognised as an internal or external command, operable program or batch file

查看:63
本文介绍了'qunit' 不是内部或外部命令,也不是可运行的程序或批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 qunit,使用命令:

I installed qunit, using command:

npm install -g qunit

然后,我编写了一个测试程序,并将文件命名为 firstTest.js.firstTest.js 的内容是:

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();  
    },  
};  

关于执行命令:

qunit firstTest.js

我得到 'qunit' 不是内部或外部命令,也不是可运行的程序或批处理文件.我该怎么办?

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

推荐答案

好的,首先,这不是你编写 QUnit 测试的方式.您可以阅读此处的文档,但本质上您需要编写浏览器可以解释的代码,并且模块.exports 不是浏览器对象,它只存在于 Node 中.

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.

现在,如果您正在使用其他一些 Node 模块,让您以这种方式编写测试,那么酷!但是,如果您使用的是基本的 qunit 模块,则无法以这种方式编写测试.以下是如何在适当的 QUnit 中编写该测试:

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");
});

现在您需要在 HTML 文件中加载该测试文件并在浏览器中打开它:

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>

其次,QUnit 没有捆绑的 CLI 可执行程序.您将需要使用另一个模块从命令行运行该测试.类似于任务运行程序 Gruntgrunt-contrib-qunit 插件.

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.

这篇关于'qunit' 不是内部或外部命令,也不是可运行的程序或批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆