Javascript 这是否违反了任何测试原则?
我使用Jasmine.js编写js单元测试,不确定这种代码是否违反了任何类型的测试原则: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
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
,因为这是您的示例中要通过的。回答了我所有的问题&更多。回答得很好,谢谢。回答了我所有的问题&更多。回答得很好,谢谢。