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

如何可靠地執(zhí)行通過 phantomjs 使用 requirejs 的 Ja

How do I reliably execute Jasmine tests that utilize requirejs via phantomjs?(如何可靠地執(zhí)行通過 phantomjs 使用 requirejs 的 Jasmine 測試?)
本文介紹了如何可靠地執(zhí)行通過 phantomjs 使用 requirejs 的 Jasmine 測試?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我正在使用 phantomjs 運(yùn)行 jasmine 測試.我的 jasmine 測試在 describe 塊周圍使用 require 以確保加載所有正確的模塊.

I am using phantomjs to run jasmine test. My jasmine tests are using require around the describe blocks to ensure all the right modules are loaded.

我的測試無法運(yùn)行,因?yàn)?page.evaluate ->jasmine.getEnv().execute(); 在 requirejs 完成加載模塊之前運(yùn)行.

My tests would not run because page.evaluate -> jasmine.getEnv().execute(); runs BEFORE requirejs finishes loading the modules.

我想知道是否有人知道解決此問題的真正好方法.我有一個答案,我將在下面發(fā)布,但很想通過其他答案比較筆記.如果你的更好,我會明確選擇它作為答案:)

I was wondering if anyone knows a real good way around this. I have an answer I'm going to post below but would love to compare notes via other answers. If yours is better, I will def pick it as answer obviously :)

推薦答案

我的解決方案,使用 jQuery,是這樣的:

My solution, with jQuery available, is this:

在您的任何測試運(yùn)行之前加載配置文件.

Load a config file before any of your tests run.

var jasmine_deferreds = [];

// Setup an event to fire on the document
// I actually did this with native code rather than jquery because
// I wanted to minimize jquery usage

// ....

// setTimeout so all files loaded after this will finish registering their requires
setTimeout( function() {

  $.when.apply( null, jasmine_deferreds ).then( function() {

    // Fire event that was created

  });

}, 5 );

如何構(gòu)建延遲數(shù)組然后解決它們?nèi)Q于您.我基本上推到了數(shù)組,然后在要求完成后解決.我用我自己的版本包裝了 require ,它知道在完成后自動解決它 - 所以我不需要在每個測試中手動推送和解決.

It's up to you how you want to build up the array of deferreds and then resolve them. I essentially pushed to the array and then resolved when the require was done. I wrapped require with my own version that would know to resolve it upon completion automatically - so I don't need to push and resolve manually in each test.

然后在我的幻像文件中我這樣做:

Then in my phantom file I do this:

page.evaluate ->
    mylistener = ( document ) -> jasmine.getEnv().execute();
    document.addEventListener( 'test_ready_event', mylistener, false);

這使得我知道我所有的 require 模塊都被加載了,而沒有一些任意的 setTimeout 一旦我加載太多文件就可能太短了.我正在使用的 setTimeout 是安全的,因?yàn)樗鼉H用于在主調(diào)用堆棧完成后觸發(fā).它并不關(guān)心時間.

This makes it so I know all my require modules are loaded without having some arbitrary setTimeout that could be too short once I am loading too many files. The one setTimeout I'm using is safe because it's only being used to fire after main callstack is done. It doesn't really care about the time.

這篇關(guān)于如何可靠地執(zhí)行通過 phantomjs 使用 requirejs 的 Jasmine 測試?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認(rèn)為文檔“準(zhǔn)備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發(fā)技術(shù)
What do jasmine runs and waitsFor actually do?(jasmine 運(yùn)行和等待實(shí)際上是做什么的?)
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 對鏈?zhǔn)椒椒ㄟM(jìn)行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監(jiān)視函數(shù)中的函數(shù)調(diào)用?)
主站蜘蛛池模板: av片在线观看网站 | 国产精品视频网站 | 国产高清视频 | 久久99精品久久久久久青青日本 | 国产精品免费福利 | 亚洲精品v日韩精品 | 久久这里只有精品首页 | 国产亚洲欧美在线 | 美女视频黄的 | 91观看| 精品国产99 | 久久久成人免费视频 | 久久久久久久一区 | 九九热最新地址 | 国产精品1| 91玖玖| 久久99精品久久久久蜜桃tv | 久久伊人影院 | 在线观看www高清视频 | 国产欧美久久一区二区三区 | 一二区成人影院电影网 | 精品国产成人 | 91精品久久 | 亚洲精品欧洲 | cao视频 | jⅰzz亚洲| 99精品欧美一区二区三区 | 成人自拍视频网站 | 中文字幕在线观看av | 天天色综 | h视频免费在线观看 | 欧美日韩第一页 | 中文字幕第十五页 | 日韩视频中文字幕 | 国产精品成人国产乱一区 | 在线中文字幕av | 日韩成人精品一区二区三区 | 色综合久久88色综合天天 | 国产精品久久久久久久久免费樱桃 | 国产在线网址 | 国产视频福利在线观看 |