茉莉花 - 间谍属性进入 jquery.post 回调

jasmine - spy property into jquery.post callback

本文关键字:jquery post 回调 间谍 属性 茉莉花      更新时间:2023-09-26

与茉莉花。我试图断言属性是否在$.post后发生了变化,我的意思是它的回调。

$.post(x,x,function(){
   boolean = true;            <--- need to assert this
})

因为我真的不希望我的测试与我可以间谍的 $ 耦合,比如。

spyOn($,'post')

这有效,但我正在覆盖我的原始回调,我的布尔值永远不会改变。

我可以使用"。CallThrough",但我不想真的做帖子,这是一个测试。

知道如何解决吗?我想错了?

谢谢!!!

我会从:

$.post(x,x,function(){
   boolean = true;            <--- need to assert this
});

自:

function callback(){
    boolean = true;
}
$.post(x,x,callback)

并且只测试回调。