Monday 29 May 2017

Assigning global variables in a jasmine helper file

I am beginning to do some unit testing for my express app using jasmine, I would like to know if anybody knows of a way in which I can assign a variable in my spec-helper.js file that I can use in all of my specs. This is what I have so far:

spec-helper.js

var baseUrl = '';

beforeAll(() => {
    baseUrl = 'http://localhost:8080/';
});

and I would like to use the baseUrl in my router.spec.js file (ideally without having to import anything into the spec file, not sure if this is possible)

router.spec.js

import * as request from 'request';

describe("Express Server", function() {
  describe("Get /", () => {
    it("returns status code 200", (done) => {
      request.get(baseUrl, (error, response, body) => {
        console.log(baseUrl);
        expect(response.statusCode).toBe(200);
        done();
      });
    });
  });
});

The helper is fired before the test, but it is saying that "baseUrl is not defined", would anybody have any advice on this?



via Shawn

No comments:

Post a Comment