gpt4 book ai didi

javascript - Jasmine beforeeach 与变量等于值的区别

转载 作者:行者123 更新时间:2023-11-28 08:38:47 25 4
gpt4 key购买 nike

谁能告诉我下面的 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');
});
});

最佳答案

无,因为每个描述中只有一个测试,请尝试以下操作:

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);
});
});

关于javascript - Jasmine beforeeach 与变量等于值的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20748717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com