让我的 mocha 测试了解我的测试类(在浏览器中运行 Mocha)的约定是什么?由于两者都包装在闭包中,因此都不在全局范围内......
猴子规格咖啡
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>