【问题标题】:Jasmine - Load nested describes from external files?Jasmine - 从外部文件加载嵌套描述?
【发布时间】:2020-07-28 03:42:16
【问题描述】:

我正在使用 Jasmine 和 Protractor 和 AngularJS 编写 e2e 测试。我有一个描述页面的父描述,以及 beforeAll 中的一些设置调用,这些调用会转到正确的页面以进行以下测试。我已将这些测试分解为每个功能的多个描述。这是一个例子:

describe('Page Detail', () => {
 beforeAll(() => {
     utils.doSomething();
 })
 describe('Location Section'), () => ...
 describe('Information Section', () => ...

我遇到的问题是这个模块中有很多功能,并且测试开始推送 300-400 行代码。理想情况下,我希望将嵌套描述放在单独的文件中并导入它们。我做过这样的事情:

 const describeLocation = require('./folder/location'),
       describeInformation = require('./folder/information');
describe('Page Detail', () => {
  beforeAll(() => {
      utils.doSomething();
  })

  describeLocation();
  describeInformation();

在其他文件中,我只是导出一个匿名函数并包含嵌套描述的代码。这可行,但不幸的是测试没有茉莉花上下文(无法访问 beforeAll 中的任何内容)。

我很好奇是否有标准或更好的方法来实现这一点?

【问题讨论】:

    标签: node.js jasmine protractor


    【解决方案1】:
    //export.js
    
    describe(...
    
    )
    
    //Import or your main specs file
    
    describe('',()=>{
    require('./export');
    })
    

    不要以方法的形式导出,只需编写规范并在主描述中使用 require 导入即可。

    【讨论】:

    • 谢谢!不敢相信我没有想到这一点。
    猜你喜欢
    • 1970-01-01
    • 2014-01-01
    • 2012-07-25
    • 2020-04-19
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    相关资源
    最近更新 更多