不能在 QUnit 测试中使用从 http url 引用的 jQuery

Can't use jQuery referenced from a http url in a QUnit test

本文关键字:url http 引用 jQuery QUnit 测试 不能      更新时间:2023-09-26

我尝试在我的QUnit测试中包含jquery,如下所示:

/// <reference path="http://code.jquery.com/jquery-2.1.3.min.js" />

但是,这一行:

var input = $("<input type='text'/>");

会给我这样的错误:

1.在测试 #1 中死亡:"$"未定义

为什么?

我假设你正在Visual Studio中进行.NET开发?那是我唯一见过/// <reference ... />东西的地方。这实际上并不包括页面中的源代码,它仅用于 IDE 中的智能感知引用。如果你想在你的测试中排除jQuery,那么你需要把它包含在你的QUnit HTML文件中,并带有一个<script>标签,就像任何其他引用一样:

<html>
  <head>
    <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    <!-- and then all of your QUnit stuff... -->
    <link rel="stylesheet" href="path/to/qunit.css">
    <script src="path/to/qunit.js"></script>
    <script src="path/to/your/tests.js"></script>
  </head>
  <body>
    <div id="qunit"></div>
  </body>
</html>