Grouping helper functions used in testing


I’ve a bunch of functions used in one jasmine test file to create test data. Like this:

var filename = "test_SomeType";
describe(filename, function() {
  var ctx;
  beforeAll(function() {
    ctx = TestApi.createContext(filename);
    . . .
  afterAll(function() {
    . . .
  // some tests
   it("should ...", function() {});
  // helper functions
  function createData() {}
  function createMoreData() {}
  function createMoreMoreData() {}

I want to reuse these helper functions in another test file.

Q: How I should extract these helper funtions and group them in an external file, then call them from both test files?


You can either create a type with this functionality or remix the TestApi type.

If you’re using TestApi in any of the helper functions, make sure your functions are marked as js client or js all so that they execute in the same runtime as your test and can modify the TestApiContext state appropriately. (Otherwise teardown will not be able to clean up all objects)

1 Like

Thanks @matt for the suggestion, I found a sample code that does this but it does not feel clean to put some test logic inside src package and expose it to other types!
No other ways?


You could put it in /test/src instead

1 Like