title: mocha javascript unit testing a function that return html string
body: <p>i have a function that return a html string "" from array,</p>
  
  <p>trying to write a mocha test for it. but the white spaces and \n are giving me hard time if i try to assert identical, and its not also flexiable to test html as if its string !.</p>
  
  <p>how do you write tests for pure functions that return html strings ?</p>
  
  <p>example:</p>
  
  <pre><code>renderHtml(json){
    // .. function that parse json and return &lt;table&gt; of its content.
  }
  </code></pre>
  
  <p>how can i test this function ?</p>
  
  <pre><code>  var mod = require('./render');
    var count = (s1,s2) =&gt; (s1.match(new RegExp(s2, 'gi'))||[]).length;
    describe('should handle simple array', function () {
      let json = [{ "id": "1", "name": "momen" }];
      let result = mod.renderHtml(json);
  
      it('should have 1 h1', function () {
        assert.equal(count(result, '&lt;h1&gt;'), 1);
      })
  
      it('should have 4 ths', function () {
        assert.equal(count(result, '&lt;th&gt;'), 4);
      })
  
      it('should have 2 tr', function () {
        assert.equal(count(result, '&lt;tr&gt;'), 2);
      })
  
      it('should have 2 td', function () {
        assert.equal(count(result, '&lt;td&gt;'), 2);
      })
    })
  </code></pre>
  
  <p>i want to test result to be contain  tag, and table with X number of ths and X number or rows that contain X number of tds each row </p>