Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.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 茉莉花测试toEqual是正确的值,但测试仍然失败_Javascript_Jasmine - Fatal编程技术网

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

});