0

让我的 mocha 测试了解我的测试类(在浏览器中运行 Mocha)的约定是什么?由于两者都包装在闭包中,因此都不在全局范围内......

找不到 Monkey 类,因为它不是全球性的,我想......


猴子规格咖啡

describe "Monkey", ->
  it "adds two to the given number", ->
    expect Monkey.add2(4).to.equal(6)

猴子咖啡

class Monkey

test_runner.html

<!DOCTYPE html>
<html>
  <head>
    <title>Mocha Test Runner</title>
    <meta charset="utf8">
    <link rel="stylesheet" href="mocha.css">
    <script src="mocha.js"></script>
    <script src="expect.js"></script>
    <script>
      mocha.setup('bdd');
    </script>

    <!-- Load in files under test -->
    <script src="monkey.js"></script>

    <!-- Load in spec files -->
    <script src="monkey.spec.js"></script>
  </head>
  <body>
    <div id="mocha"></div>

    <script>
      mocha.run();
    </script>
  </body>
</html>
4

1 回答 1

2
class Monkey

创建一个Monkey在文件范围内的类。你要

class window.Monkey

或者

class @Monkey

简而言之。

于 2012-05-03T01:39:09.717 回答