gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 787 forks source link

Code coverage miss when using window.location.href #863

Closed prajapati-parth closed 6 years ago

prajapati-parth commented 6 years ago

I encountered a strange issue where I was trying to cover a function in react class that was of the following kind

class xyz extends React.Component {
  doRedirect() {
    // other code
    const url = '/456'
    window.location.href = url;
  }
}

Trying to hit the code doesn't work. But commenting out the line window.location.href = url hits the code.

What I've tried so far: I thought accessing window might throw an exception but doing console.log(window) it logs a window object.

zivyangll commented 5 years ago

+1

zivyangll commented 5 years ago

@prajapati-parth I also encountered this problem, how did you solve it?

prajapati-parth commented 5 years ago

@zivyangll I do not exactly remember as this has been like an year ago but looking at the git history it seems like I changed window.location.href = "https://some.url.com" to window.location.assign("https://some.url.com").