Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.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,我使用Jasmine.js编写js单元测试,不确定这种代码是否违反了任何类型的测试原则: expect(someObject).toNotBe(undefined || null); 相对于 expect(someObject).toNotBe(undefined); expect(someObject).toNotBe(null); 尽管null和undefined是不同的,但就我的测试而言,我并不(认为我)在乎它是哪一个。undefined | | null返回null,因为undefi

我使用Jasmine.js编写js单元测试,不确定这种代码是否违反了任何类型的测试原则:

expect(someObject).toNotBe(undefined || null);
相对于

expect(someObject).toNotBe(undefined);
expect(someObject).toNotBe(null);

尽管
null
undefined
是不同的,但就我的测试而言,我并不(认为我)在乎它是哪一个。

undefined | | null
返回
null
,因为
undefined
是错误的:

> undefined || null
null
第一个示例实际上相当于第二个示例的第二行,即:

expect(someObject).toNotBe(null);
另外,
toNotBe

旧的匹配程序
toNotEqual
toNotBe
toNotMatch
toNotContain
已被弃用,并将在将来的版本中删除。请将您的规格更改为分别使用
not.toEqual
not.toBe
not.toMatch
not.toContain

您可能希望使用
null
检查是否相等(而不是标识!),如
false!=空
,但
未定义==空

expect(someObject).not.toEqual(null);
如果
someObject
false
0
[]
等也是不可取的,您还可以执行以下操作:

expect(someObject).toBeTruthy();

否则,您应该编写自己的匹配程序。

undefined | | null
返回
null
,因为
undefined
是错误的:

> undefined || null
null
第一个示例实际上相当于第二个示例的第二行,即:

expect(someObject).toNotBe(null);
另外,
toNotBe

旧的匹配程序
toNotEqual
toNotBe
toNotMatch
toNotContain
已被弃用,并将在将来的版本中删除。请将您的规格更改为分别使用
not.toEqual
not.toBe
not.toMatch
not.toContain

您可能希望使用
null
检查是否相等(而不是标识!),如
false!=空
,但
未定义==空

expect(someObject).not.toEqual(null);
如果
someObject
false
0
[]
等也是不可取的,您还可以执行以下操作:

expect(someObject).toBeTruthy();

否则,您应该编写自己的匹配程序。

如果您不在乎,就通过
null
,因为这是您的示例中要通过的。如果您不在乎,就通过
null
,因为这是您的示例中要通过的。回答了我所有的问题&更多。回答得很好,谢谢。回答了我所有的问题&更多。回答得很好,谢谢。