Javascript 茉莉花测试toEqual是正确的值,但测试仍然失败
我正在写一系列测试来证明“这”在不同环境中的价值 以下是我当前的测试套件:Javascript 茉莉花测试toEqual是正确的值,但测试仍然失败,javascript,jasmine,Javascript,Jasmine,我正在写一系列测试来证明“这”在不同环境中的价值 以下是我当前的测试套件: describe("this keyword", function(){ it('returns the global context of this', function(){ expect(globalThis()).toEqual(window); }); it('returns the method context of this', function(){
describe("this keyword", function(){
it('returns the global context of this', function(){
expect(globalThis()).toEqual(window);
});
it('returns the method context of this', function(){
expect(methodThis.showThis()).toEqual({ showThis : Function });
});
});
我的第二个测试不会通过此代码,即使它是精确的值:
var methodThis = {
showThis: function(){
return this;
}
};
该函数所做的一切就是在对象内部返回该对象的上下文
为什么即使将正确的toEqual值传递给toEqual,该测试仍会失败?您可以用于比较函数类型:
describe("this keyword", function(){
it('returns the method context of this', function(){
expect(methodThis.showThis()).toEqual({ showThis : jasmine.any(Function) });
});
});