Albin Mathew
Albin Mathew

Reputation: 604

Test Case for typeof window undefined

How can we test else case for window. In My test cases it checks the if statement. But coverage shows else part not taken. How can we test that.

function sample(){
  if(typeof window !== undefined){
    doSomething()
  }
}  

Upvotes: 1

Views: 600

Answers (1)

Thaadikkaaran
Thaadikkaaran

Reputation: 5226

You can use /* istanbul ignore else */ to ignore the else part coverage.

For your case,

function sample(){
  /* istanbul ignore else */
  if(typeof window !== undefined){
    doSomething()
  }
} 

Check here for the other options.

Upvotes: 1

Related Questions