user3200120
user3200120

Reputation:

Jasmine - Load nested describes from external files?

I'm writing e2e tests using Jasmine and Protractor with AngularJS. I have a parent describe which describes the page, and some setup call in beforeAll that goes to the correct page for the following tests. I've broken these tests up into multiple describes per feature. Here is an example:

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

The problem I'm having is that there are a lot of features within this module, and the tests are starting to push 300-400 lines of code. I would ideally like to put the nested describes in seperate files and import them. I've done something like this:

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

  describeLocation();
  describeInformation();

In the other files I'm simply exporting an anonymous function and including the nested describe's code. This works, but unfortunately the tests don't have the jasmine context (can't access anything in beforeAll).

I'm curious if there is a standard or better way to accomplish this?

Upvotes: 2

Views: 209

Answers (1)

Bharath Kumar S
Bharath Kumar S

Reputation: 1408

//export.js

describe(...

)

//Import or your main specs file

describe('',()=>{
require('./export');
})

Don't export in a form of a method just write your spec and import it using require in the main describe.

Upvotes: 0

Related Questions