Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 茉莉花以前受到兄弟姐妹的影响_Javascript_Unit Testing_Jasmine - Fatal编程技术网

Javascript 茉莉花以前受到兄弟姐妹的影响

Javascript 茉莉花以前受到兄弟姐妹的影响,javascript,unit-testing,jasmine,Javascript,Unit Testing,Jasmine,我的印象是,beforeAll-函数只会运行一次,以描述它所包含的内容。然而,兄弟姐妹的描述似乎会影响以前的 可以找到以下测试 我希望“Second description”中的beforeAll将有一个空的testArray,因为“outer description”在每个之前都有一个将其初始化为空数组。但是,在“第二次描述”的beforeal中,testArray在“第一次描述”的beforeach中添加了一项 这有意义吗?如果是这样的话,有人能解释一下beforeal是如何工作的吗 注意:

我的印象是,
beforeAll
-函数只会运行一次,以描述它所包含的内容。然而,兄弟姐妹的描述似乎会影响以前的

可以找到以下测试

我希望“Second description”中的
beforeAll
将有一个空的
testArray
,因为“outer description”在每个
之前都有一个
将其初始化为空数组。但是,在“第二次描述”的
beforeal
中,
testArray
在“第一次描述”的
beforeach
中添加了一项


这有意义吗?如果是这样的话,有人能解释一下beforeal是如何工作的吗

注意:您的代码中有一个输入错误;)。。但这不是问题所在

expect(arrIsEmptyInBeforeAll).toBeTruthy();
简短回答

在茉莉花中,beforeAll总是被称为beforeach,即使有外部beforeach语句

您的测试按以下方式执行:

(外部测试的迭代)

  • 调用外部beforeach->数组为空
  • 调用之前的“第一次描述->数组变为长度=1
  • (内部测试的迭代)

  • 调用“Second description”beforeAll->arrisemptyinbforeall为false,因为数组仍然设置了一个项
  • 调用外部beforeach->数组为空
  • 调用beforeach之前的“Second description”->arrisemptyinbforeach为true,因为数组已清除
  • ArrisemptyinBefore在你的测试中是错误的

  • 好的,我觉得文档中没有明确说明这一点。。。我觉得有点奇怪,外部的描述是在内部的描述之后进行的。但这个执行令解释了我的问题。谢谢
    expect(arrIsEmptyInBeforeAll).toBeTruthy();