Vish
Vish

Reputation: 139

Jasmine: How to pass test suite function to describe method?

What I am doing:

I am using jasmine to test my javascript functions. My describe function & it functions are in different files.

What I want to do:

I am trying to pass parameter to describe function but i am getting an error.

My code:

describe("Test file-utils funtions",fileUtilsFunc("abc"))
// Getting Error: describe expects a function argument; received [object Undefined]

It is not allowing to pass "abc" parameter.

Upvotes: 0

Views: 840

Answers (1)

M. Twarog
M. Twarog

Reputation: 2611

Probable Issue

Describe expects two arguments:

  • String with description of test suite
  • Function containing test cases (i.e. containing "it" parts)

In your code you are passing the former correctly, but the latter is not a name of a function, but a function call which will be evaluated. Unless your fileUtilsFunc function returns another function it won't work. fileUtilsFunc returning undefined appears to be a problem with your code.

Solution

You should try passing function with test cases:

describe("Test file-utils funtions",fileUtilsFunc)

function fileUtilsFunc() {
  it("Test case name", function() {/*test case code*/});
}

Or function which returns function with test cases:

describe("Test file-utils funtions",fileUtilsFunc())

function fileUtilsFunc() {
  return function() {
    it("Test case name", function() {/*test case code*/});
  }
}

Notice difference between fileUtilsFunc in first example and fileUtilsFunc() in second example.

Upvotes: 2

Related Questions