簡體   English   中英

如何在 gruntfile 上配置茉莉花的隨機數?

[英]How can I configure the jasmine's random on gruntfile?

如何使用 grunt-contrib-jasmine 配置隨機選項? 我可以直接用 jasmine 的命令行來完成,但是通過 grunt-cli 運行 jasmine 的任務我沒有找到隨機選項。 然后命令行的輸出總是顯示規范的隨機輸出。

我找到了我的問題的答案。 至少我已經測試過並且有效。 在每個描述聲明的頂部,您可以配置您的套裝測試的隨機選項。 它可以與以下語句一起使用:

describe('My suite', function(){
   jasmine.getEnv().configure({random:false});

   // There are several tests here... 

   afterAll(function(){
      jasmine.getEnv().configure({random:true});
   });

   ...

如果你使用 jasmine.d.ts 並且你的測試是在打字稿中,你還可以在 jasmine.d.ts 的 Env 接口中添加一個類似的功能:

interface Env {
    // some code
    // add function:
    configure(b: any): void;
}

然后在您的測試中,您可以編寫如下內容:

/// <reference path="../../../../typings/jasmine/jasmine.d.ts" />
jasmine.getEnv().configure({ random: false });

我測試了這種方法,最后我不必在每個描述函數中將隨機選項設置為 false。 我在參考路徑之后添加了它,它適用於所有測試。

編輯:您還可以將 jasmine 配置作為單獨的文件包含在 grunt-contrib-jasmine 任務的 options/helpers 部分。 就像是:

jasmine: {
    src: [some source files],
    options: {
      specs: [some spec files],
      helpers: 'helpers.js'
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM