如何在Jasmine测试中包含Ext JS

时间:2013-11-17 15:14:22

标签: javascript unit-testing extjs jasmine

我是Jasmine的新手。我想测试一个Ext JS应用程序。

当我运行测试时,浏览器抛出以下内容:

ReferenceError:未在Ext.create('xxxx.application.store.SystemHealth')行上定义Ext;

这是我的SpecRunner.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Jasmine Spec Runner</title>

  <link rel="shortcut icon" type="image/png" href="lib/jasmine- 1.3.1/jasmine_favicon.png">
  <link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>



  <!--include source files here... -->
 <!--<script type="text/javascript" src="spec/SpecHelper.js"></script>-->
  <!--<script type="text/javascript" src="specs/example.spec.js"></script>-->

 <!-- include spec files here... -->
 <!--<script type="text/javascript" src="src/Player.js"></script>-->
 <!--<script type="text/javascript" src="src/Song.js"></script>-->
 <script type="text/javascript" src="src/SystemHealth.js"></script>

 <script type="text/javascript">
(function() {

  var jasmineEnv = jasmine.getEnv();
  jasmineEnv.updateInterval = 1000;

  var htmlReporter = new jasmine.HtmlReporter();

  jasmineEnv.addReporter(htmlReporter);

  jasmineEnv.specFilter = function(spec) {
    return htmlReporter.specFilter(spec);
  };

  var currentWindowOnload = window.onload;

  window.onload = function() {
    if (currentWindowOnload) {
      currentWindowOnload();
    }
    execJasmine();
  };

  function execJasmine() {
    jasmineEnv.execute();
  }

})();
 </script>

</head>

<body>

   

我希望它足够清楚。

2 个答案:

答案 0 :(得分:0)

在ExtJS中使用jasmine lib编写的示例代码:

      <head>
        <title>Extjs - Unit testing demo</title>
        <link rel="stylesheet" type="text/css" href="app-test/lib/jasmine-1.3.1/jasmine.css"></link>
        <script type="text/javascript" src="../ext4.1.3/ext-debug.js"></script>
        <script type="text/javascript" src="app-test/lib/jasmine-1.3.1/jasmine.js"></script>
        <script type="text/javascript" src="app-test/lib/jasmine-1.3.1/jasmine-html.js"></script>


        <!-- specs test files -->
        <script type="text/javascript" src="app-test/specs/example.js"></script>
        <script type="text/javascript" src="app-test/specs/users.js"></script>

        <!-- Extjs app launcher -->
        <script type="text/javascript" src="app-test.js"></script>
   </head>
   <body></body>

希望它有所帮助!!

答案 1 :(得分:0)

谢谢,是的,我需要添加以添加以下行:

    <script type="text/javascript" charset="utf-8" src="http://cdn.sencha.io/ext-4.1.1-
     gpl/ext-all-dev.js"></script>
     <script src="../../../../../../.ext-js/sencha-ext-js-4.1.1a/ext.js"  
      type="text/javascript"></script>