Jasmine beforeEach 未调用

Jasmine beforeEach not called

刚开始使用 Jasmine 并按照 the Jasmine website 上的说明进行异步测试时,我注意到从未调用过 beforeEach 函数。

知道为什么不吗?我在网络上的任何地方都找不到任何相关的提示。谢谢

代码

代码真的很简单:

describe("Testing test.php", function()
{
    it ("Gets me a coke", function()
    {
        var asyncResult = null;

        // query function with callback
        var queryFcn = function(callback)
        {
            console.log("queryFcn");
            $.get("be_com/test.php?coke")
            .success(function(data)
            {
                asyncResult = data.response;
                callback(); // notify jasmine
            })
            .error(function() { callback(); });
        };

        // Call ajax
        beforeEach(function(done) { 
            console.log('beforeEach');
            queryFcn(done); });

        // Evaluate response
        expect(asyncResult).toBe("a can of coke");
    });
});

HTML同样简单:

<html>
<head>
<link rel="shortcut icon" type="image/png" href="../fe_com/js/lib/jasmine-standalone-2.3.4/lib/jasmine-2.3.4/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="../fe_com/js/lib/jasmine-standalone-2.3.4/lib/jasmine-2.3.4/jasmine.css">

<script type="text/javascript" src="../fe_com/js/lib/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="../fe_com/js/lib/jasmine-standalone-2.3.4/lib/jasmine-2.3.4/jasmine.js"></script>
<script type="text/javascript" src="../fe_com/js/lib/jasmine-standalone-2.3.4/lib/jasmine-2.3.4/jasmine-html.js"></script>
<script type="text/javascript" src="../fe_com/js/lib/jasmine-standalone-2.3.4/lib/jasmine-2.3.4/boot.js"></script>

<!--   FILES -->
<script type="text/javascript" src="testSpec.js"></script>
</head>

<body>
    <h2>Unit Tests</h2>
</body>
</html>

beforeEach 块不应位于 it 块内。

beforeEach 的想法是其中的代码在以下每个 it 块 之前运行 。示例:

beforeEach(function () {
    // code in here will run 3 times
});

it('does first thing', function () {});
it('does a second thing', function () {});
it('does a third thing', function () {});