title: Use of conditional statements in Jasmine tests
body: <p>I have two functions I want to test; one that runs only in "modern browsers" the other that runs only in "older" browsers.</p>
  
  <p>I am using Jasmine as my testing framework and Karma to run my tests. Karma will launch many browsers in which all the tests are run.</p>
  
  <p><strong>My problem</strong> is that testing ALL my functions in ALL browsers will lead some tests to fail. For example, testing a function that should run only in modern browsers will fail in when tested in IE8.</p>
  
  <p>Code to test:</p>
  
  <pre><code>function getStuffFromSmartBrowser() {
      return 'foo';
  }
  
  function getStuffFromNotSoSmartBrowser() {
      return 'bar';
  }
  
  if ('intelligence' in browser) {
      getStuffFromSmartBrowser();
  } else {
      getStuffFromNotSoSmartBrowser();
  }
  </code></pre>
  
  <p>Original test code:</p>
  
  <pre><code>describe("A suite", function () {
      it("for smart browsers", function () {
          expect(getStuffFromSmartBrowser()).toEqual('foo');
      });
  });
  
  describe("A suite", function () {
      it("for not so smart browsers", function () {
          expect(getStuffFromNotSoSmartBrowser()).toEqual('bar');
      });
  });
  </code></pre>
  
  <p>In these test cases, one test will fail in one type of browsers while the other test will fail in the other type of browsers.</p>
  
  <p>Alternative test code:</p>
  
  <pre><code>describe("A suite", function () {
      if ('intelligence' in browser) {
          it("for smart browsers", function () {
              expect(getStuffFromSmartBrowser()).toEqual('foo');
          });
      } else {
          it("for not so smart browsers", function () {
              expect(getStuffFromNotSoSmartBrowser()).toEqual('bar');
          });
      }
  });
  </code></pre>
  
  <p>The alternative test code run perfectly well in all tested browsers.</p>
  
  <p><strong>Questions:</strong></p>
  
  <p><strong>A - Is it good practice to use conditional statements in tests?</strong></p>
  
  <p><strong>B - If not, what would be a better approach?</strong></p>