javascriptunit-testingphantomjsgrover

How to skip the code execution from PhantomJS or grover


The problem is next: I have JavaScript code in my application and I want to skip/hide some peace of code from PhantomJS and grover checking/execution.

So, how can I skip/hide the code execution from PhantomJS or grover?

Note: the problem has occurred when I was writing the JavaScript unit-tests. But I think it would be helpful in other cases.


Solution

  • You just need to wrap the code with simple verification:

    if (!window['phantom'] && !window['_phantom']) {
      // your code here...
    }
    

    In this case the code in your application will be executed as normal but skipped when the PhantomJS or grover will inspect it.

    Notes: