久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Spec沒有期待——Jasmine測試回調函數

Spec has no expectations - Jasmine testing the callback function(Spec沒有期待——Jasmine測試回調函數)
本文介紹了Spec沒有期待——Jasmine測試回調函數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個使用 d3 計時器 調用的方法.每當調用該方法時,該方法都會發出一個帶有幾個值的對象.其中一個值隨時間增加.我想編寫一個測試來檢查這些值是否按升序排列(即是否隨時間增加).

I have a method which is being called using a d3 timer. Whenever the method is called, the method emits an object with a couple of values. One of the values increases over time. I would like to write a test to check whether the values are in the ascending order or not (i.e., increasing over time or not).

因此,為了解決這個問題,在我的測試中,我訂閱了事件發射器,在訂閱中,我將收到的對象推送到本地數組中.然后,我期望 array[i] 小于 array[i+1].我認為我的邏輯是完全正確的,但我不確定為什么我從 Jasmine 那里得到一個錯誤,說 規范沒有期望,即使我有一個.

So, to tackle this, In my test, I subscribe to the event emitter and inside the subscription, I am pushing the object which I receive into a local array. And then, I am expecting the array[i] to be less than the array[i+1]. I think my logic is perfectly correct but I am not sure why I am getting an error from Jasmine saying that the spec has no expectations even though I have one.

代碼如下:

let x = d3.timer((elapsed) => { 
    this.method(); // call the function
    if(elapsed >= 500) {
     x.stop(); // stops the timer.
    }
});

method(elapsed) {
 // do something
 if(elapsed > 500) {
   this.output.emit({x: somevalue, y: somevalue, f: increasingvalue });
 }
}

茉莉花規格:

it('my spec', inject([JumpService], (service: JumpService) =>{
  array = [];
  //service calls the method
  service.output.subscribe(e => {
   array.push(e);
   // A console statement here will give me the length and the object pushed.
   for(let i = 0; i< array.length - 1; i++) {
    expect(array[i].f).toBeLessThan(array[i+1].f);
   }

  });

}));

我在這里做錯了嗎?我該如何應對這種情況?請指導我正確的方向.

Am I doing anything wrong here? How can I tackle such kind of a scenario? Please guide me in a right direction.

謝謝.

推薦答案

一般來說,在測試異步回調函數時,在 promise 解決后期待測試的輸出總是很重要的.您可以將 Angular 測試臺框架的 tick()fakeAsync() 一起使用,或者您可以簡單地回退到 Jasmine 使用 測試異步方法的一般方式完成()

In general, when testing the async callback functions, it is always important to expect the outputs of the test after the promises are resolved. You can use the Angular test bed framework's tick() with the fakeAsync() or you can simply fallback to the Jasmine's general way of testing the async methods by using done()

使用 done():

it('my spec', (done) => {
  array = [];
  service.output.subscribe(e => {
   array.push(e);
   for(let i = 0; i< array.length - 1; i++) {
    expect(array[i].f).toBeLessThan(array[i+1].f);
   }
   done();
  });
});

希望這個答案有所幫助.

Hope this answer helps.

注意:我對 fakeAsync()tick() 的運氣并不好,所以我沒有將其包含在答案中.對此感到抱歉.

Note: I didn't had great luck with the fakeAsync() and tick(), so I am not including it in the answer. Sorry about that.

這篇關于Spec沒有期待——Jasmine測試回調函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 亚洲一区二区精品视频在线观看 | 成人在线视频免费观看 | 91久久夜色 | 天堂成人国产精品一区 | 少妇午夜一级艳片欧美精品 | 夜夜爽99久久国产综合精品女不卡 | 欧美在线一区二区三区 | 日韩欧美国产精品 | 亚洲九九精品 | 日韩在线精品视频 | 欧美成年网站 | 亚洲成人精品久久 | 精品一区二区三区四区视频 | 亚洲视频一区在线 | 国产色婷婷精品综合在线手机播放 | 亚洲欧美日韩国产综合 | 亚洲97 | 91精品久久久久久久久中文字幕 | 亚洲在线视频 | 欧美一级视频在线观看 | 日韩在线欧美 | 99爱在线观看 | 国产激情自拍视频 | 国产成人综合亚洲欧美94在线 | 日韩高清中文字幕 | 黄色成人免费看 | 日韩久久久一区二区 | 91在线免费视频 | 日韩在线| 国产精品a久久久久 | 国产一区二| 成人精品鲁一区一区二区 | 黄网站免费在线观看 | 看av片网站 | 亚洲成人免费在线观看 | 久久国产一区二区三区 | 亚洲免费人成在线视频观看 | 免费看国产一级特黄aaaa大片 | 久久久精品国产 | 国产一级视频在线播放 | 日韩一区二区在线视频 |