差异jasmine beforeeach vs variable等于value

时间:2013-12-23 17:56:02

标签: javascript angularjs jasmine

任何人都可以告诉我以下Jasmine代码的区别,请原谅我,如果它是愚蠢的

describe('Testing a Hello World controller', function() {
    var $scope;

    beforeEach(function(){
        $scope = 'Hello World'
    });

    it('should say hello to the World', function() {
        expect($scope).toEqual('Hello World');
    });
});

describe('Testing a Hello World controller', function() {
    var $scope = 'Hello World';

    it('should say hello to the World', function() {
        expect($scope).toEqual('Hello World');
    });
});

1 个答案:

答案 0 :(得分:0)

没有,因为你在每个描述中只有一个测试,试试这个:

describe('beforeEach example', function() {
        var $scope = 0;

        beforeEach(function(){
            $scope += 1
        });

        it('should be 1', function() {
            expect($scope).toEqual(1);
        });

        it('should be 2', function() {
            expect($scope).toEqual(2);
        });
    });