敲除.js用QUNIT对象误差进行测试
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I am trying to use QUNIT to test knockout.js code. The KO code that creates the viewmodel and applies the binding is in a separate file (views.js). It is similar setup as the html I am using to call knockout. That page works fine since I get values for the binding. However I setup a test page using QUNIT with test cases and I get the following error when I try to access an element of the viewmodel.

1.Died on test #1: Object doesn't support this property or method - { "name": "TypeError", "message": "Object doesn't support this property or method", "number": -2146827850, "description": "Object doesn't support this property or method" }2.Expected 0.00 assertions, but 1 were run

As you can see by the code I tried the test case in the body as well, but I get the same error. Can someone tell me what I am doing wrong and why Knockout would work fine with the HTML page I have, but not the one with QUNIT?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
      "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
  <head>  
    <link rel="stylesheet" href="Content/qunit.css" type="text/css"/>  
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../Scripts/NRF_Items.js" type="text/javascript"></script>
    <script type="text/javascript" src="../scripts/jquery.alerts.js"></script>
    <script src="../Scripts/knockout-2.0.0.debug.js" type="text/javascript"></script>    
    <script src="../Models/GetResponse.js" type="text/javascript"></script>
    <link href="../css/jquery.alerts.css" rel="stylesheet"/>
    <script src="../Scripts/jquery.confirm.js" type="text/javascript"></script>
    <link href="../css/jquery.confirm.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="Scripts/qunit.js"></script>  
    <script type="text/javascript">

        $(document).ready(function () {
            QUnit.log = function (result, message) {
                if (window.console && window.console.log) {
                    window.console.log(result + ' :: ' + message);
                }
            }
            module("Basic Unit Test");
            test("Sample test 1", function () {
                expect(1);
                equals(divide(4, 2), 2, 'Expected 2 as the result, result was ' + divide(4, 2));
            });

            test("Sample test Knockout", function () {
                expect("0.00");
                equals(this.TransTotal(), "$0.00", 'Expected $0.00 as the result, result was ' + this.TransTotal());
            });


            function divide(a, b) {
                return a / b;
            }
        });


    </script>  
  </head>  

<body>
    <div id="price_cntnr">
      <ul id="PriceList">
      <li ><span id="SubTotal" data-bind="text: SubTotal"></span>Sub Total :</li>
          <li ><span id="TaxTotal" data-bind="text: TaxTotal"></span>Tax Total :</li>
          <li class="trans_total" ><span id="TransTotal" data-bind="text: TransTotal"></span>Trans Total :</li>
          <li ><span id="BalanceDue" data-bind="text: TransTotal"></span>Balance Due :</li>
      </ul>
    </div>
    <script type="text/javascript" src="../ViewModel/Views.js"></script>
     <script type="text/javascript">
                test("Sample test Knockout in Body", function () {
            expect("0.00");
            equals(this.TransTotal(), "$0.00", 'Expected $0.00 and the result was ' + this.TransTotal());

        });
    </script>
    <h1 id="qunit-header">QUnit example</h1>  
    <h2 id="qunit-banner" onkeypress="return qunit-banner_onkeypress()"></h2>  
    <h2 id="qunit-userAgent"></h2>  
    <ol id="qunit-tests">  
    </ol>  

  </body>  
</html>

#0

Might it be this line?

<h2 id="qunit-banner" onkeypress="return qunit-banner_onkeypress()"></h2>

qunit-banner_onkeypress() is not a valid function identifier in JS. Hyphens - are not allowed in declared function names like that.

推荐文章

最佳免费自动更新程序c#

最佳免费自动更新程序c#

推荐文章

SQL Server数据库设计:多对多关系的建议

SQL Server数据库设计:多对多关系的建议

推荐文章

使用XSLT的XML到XML转换

使用XSLT的XML到XML转换

推荐文章

C++:标识符、关键字、名称和实体有什么区别?

C++:标识符、关键字、名称和实体有什么区别?

推荐文章

从salesforce for iOS检索图像

从salesforce for iOS检索图像

推荐文章

C++编译器问题

C++编译器问题

推荐文章

在Android Gallery中,如何收听锁定的图像?

在Android Gallery中,如何收听锁定的图像?

推荐文章

django:如何更改modelform中nullbooleanfield的值?

django:如何更改modelform中nullbooleanfield的值?

推荐文章

MySQL的最佳实践

MySQL的最佳实践

推荐文章

Microsoft SQL Server迁移助手Mysql

Microsoft SQL Server迁移助手Mysql

推荐文章

在景观模式下,搜索栏和表格视图不适合屏幕

在景观模式下,搜索栏和表格视图不适合屏幕

推荐文章

拥有一对多关系

拥有一对多关系

推荐文章

为什么adMob会在Android中抛出这些空指针异常?

为什么adMob会在Android中抛出这些空指针异常?

推荐文章

如何删除尾随斜杠?

如何删除尾随斜杠?

推荐文章

MS Access内部联接最新条目

MS Access内部联接最新条目

推荐文章

SQL Server表的varbinary列中的搜索字符串

SQL Server表的varbinary列中的搜索字符串