0

I am trying to write a D.O.H. test for a function which determines if the current environment is running in either production or a local development machine. The function accomplishes this by analyzing the string in the document.domain property. Is there a way to programmatically set the document.domain property so that when the function is called from the D.O.H. test, the domain I specify will get analyzed? Here is the function:

isProdEnvironment = function() {
        var nonProdRegExp = new RegExp( 'localhost|dev|test|perf' );
        var isNonProd = nonProdRegExp.test( document.domain );
        return ! isNonProd;
    };

In my test case, I wanted to do something like:

document.domain = 'someProdEnvironment.com';
doh.assertFalse (isProdEnvironment());

However, everytime I do this, the test always passes due to the fact the document.domain call in the isProdEnvironment() function keeps retrieving the domain of the development machine that my tests are running on (i.e. 'localhost').

  • Why are you not using `window.location.hostname`? – epascarello Jul 30 '13 at 13:45
  • my understanding was that `window.location.hostname` and `document.domain` are equivalent – user2634316 Jul 30 '13 at 13:56
  • *"eeps retrieving the domain of the development machine that my tests are running on (i.e. 'localhost')."* Wait, you are running this page on localhost and wondering why it is always returning true? – epascarello Jul 30 '13 at 13:58
  • I am always running it on localhost during development, but I need make sure the function works on different domains (i.e. not localhost). That is why I wanted to know if I could programmatically set window.location.hostname or document.domain. – user2634316 Jul 30 '13 at 14:02
  • I believe it would be a security issue if that was writeable. Why don't you just use a regular variable in your test instead of document.domain? – bfavaretto Jul 30 '13 at 16:27

0 Answers0