Jasmine检查数组是否为空 - fabric js undefined

时间:2014-04-19 13:19:49

标签: javascript arrays testing jasmine fabricjs

我开始使用Jasmine对我的代码运行测试。到目前为止,大多数测试都是相当原始的,但是我在检查数组是否已经填充时遇到了问题。

测试是:

describe("create grid of layers", function() {
    var result = new Array(4);
    it("returns an array of objects as a grid", function() {
        result = randomQuadrants();
        expect( result).toBeDefined();
    });
});

我也试过了:

describe("create grid of layers", function() {
    var result = new Array(4);
    it("returns an array of objects as a grid", function() {
        expect(result = randomQuadrants()).toBeDefined();
    });
});

同时在以下代码中的ReferenceError: fabric is not defined行收到var obj = new fabric.GeologicalObject({错误。

function randomQuadrants() {
    var posX, posY;
    posY = 175;

    for (var i=0; i<10; i++){
        //declaring random num here makes each layer the same but random.
        grid[i] = new Array(6);
        posX = 100;

        for(j=0; j<10; j++) {
            //random num here makes each square a random layer
            var randomNum = random_num(layerDetails.length);
            var obj = new fabric.GeologicalObject({
                strength: layerDetails[randomNum].strength,
                minSpeed: layerDetails[randomNum].minSpeed ,
                maxSpeed: layerDetails[randomNum].maxSpeed,
                width: 200,
                height: 75,
                left:  posX,
                top: posY,
                fill: 'red'
            });

            posX = parseInt(posX) + 200;
            loadPattern(obj, layerDetails[randomNum].pattern);
            grid[i][j] = obj;
        }
        posY+=75;
    }
    return grid;
}

感谢您的帮助!

0 个答案:

没有答案