简体   繁体   English

jasmine中的条件测试用例

[英]Conditional test case in jasmine

I am writing Jasmine.我正在写 Jasmine。 I want that when the response from the site is ok (site uploaded- pending 200).我希望当网站的响应正常时(网站上传 - 待处理 200)。

Run the it's (test cases) in spec and when the site is failed to load the site the it's (test cases) will not run.在规范中运行它的(测试用例),当站点无法加载该站点时,它的(测试用例)将不会运行。

I check the response from site in before all function.我在所有 function 之前检查了来自站点的响应。

And now in each it that make different thing I check the condition if the response (saved in global var) is true现在,如果响应(保存在全局变量中)为真,我会在每一个做出不同的事情时检查条件

How can I do it in global fun like before each?我怎样才能像以前一样在全球乐趣中做到这一点?

 let response; describe('', ()=>{ beforeAll (async () => { //this function return the statusCode of http request response= await sendQuery('Http://...'); }) beforeEach(async(), =>{ }); it('', async()=> { if (response = 200){ //do somsing 1... } it('', async()=> { if (response = 200){ //do somsing 2... } it('', async()=> { if (response = 200){ //do somsing 3... } v it('', async()=> { if (response = 200){ //do somsing 4... } it('', async()=> { if (response = 200){ //do somsing 5... } it('', async()=> { if (response = 200){ //do somsing 6... }

something like this in your config在你的配置中这样的东西

async onPrepare() {

global.response = await sendQuery('Http://...');
    if (global.response !== 200) {
      throw new Error(`Status is ${response}`); // may not be needed actually, but I'll leave it
      await browser.close();
      await process.exit(1);
    }
}

global.response will be available in your specs global.response将在您的规范中可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM