<commit_before>import assert from 'assert';
import React from 'react/addons';
const TestUtils = React.addons.TestUtils;
import {fromComponent} from '../src/domnodes.js';
import DomNode from '../src/domnode.js';

function domNodesFromComponent(component) {
  return fromComponent(component).domNodes;
}

describe('dom asserts', function() {
  
  describe('find a DOM node with `attr="value"`', function() {
    it('finds none', function() {
      const component = <b></b>;
      assert.equal(rendersDomNodeWithAttrAndValue(component, 'className', 'x'), false);
    });
    it('finds a `className` in one DOM node', function() {
      const component = <b className="x"></b>;
      assert.equal(rendersDomNodeWithAttrAndValue(component, 'className', 'x'), true);
    });
    it('finds a `className` in one DOM node of many', function() {
      const component = <div><b className="x"></b></div>;
      assert.ok(rendersDomNodeWithAttrAndValue(component, 'className', 'x'));
    });
  });
});

function rendersDomNodeWithAttrAndValue(component, attributeName, expectedValue) {
  let domNodes = domNodesFromComponent(component);
  return domNodes
    .some(domNode => domNode.hasAttributeWithValue(attributeName, expectedValue))
}


//rendersDomNodeAttributeWithValue
//rendersDomNodeWithInnerText
<commit_msg>Implement first real assert function.<commit_after>import assert from 'assert';
import React from 'react/addons';
const TestUtils = React.addons.TestUtils;
import {fromComponent} from '../src/domnodes.js';
import DomNode from '../src/domnode.js';

function domNodesFromComponent(component) {
  return fromComponent(component).domNodes;
}

describe('dom asserts', function() {
  
  describe('find a DOM node with `attr="value"`', function() {
    it('finds none', function() {
      const component = <b></b>;
      assert.equal(rendersDomNodeWithAttrAndValue(component, 'className', 'x'), false);
    });
    it('finds a `className` in one DOM node', function() {
      const component = <b className="x"></b>;
      assert.equal(rendersDomNodeWithAttrAndValue(component, 'className', 'x'), true);
    });
    it('finds a `className` in one DOM node of many', function() {
      const component = <div><b className="x"></b></div>;
      assert.ok(rendersDomNodeWithAttrAndValue(component, 'className', 'x'));
    });
  });

  describe('assert function', function() {
    it('is silent when test passes', function() {
      const component = <b className="x"></b>;
      const fn = () => {
        assertFunctions.rendersDomNodeWithAttrAndValue(component, 'className', 'x');
      };
      assert.doesNotThrow(fn);
    });
    describe('when it fails', function() {
      it('throws', function() {
        const component = <b></b>;
        const fn = () => {
          assertFunctions.rendersDomNodeWithAttrAndValue(component, 'className', 'x');
        };
        assert.throws(fn);
      });
      it('throws right message', function() {
        const component = <b></b>;
        try {
          assertFunctions.rendersDomNodeWithAttrAndValue(component, 'className', 'x');
        } catch (error) {
          assert.ok(error.message.startsWith('Expected'));
        }
      });
    });
  });
  
});

function rendersDomNodeWithAttrAndValue(component, attributeName, expectedValue) {
  let domNodes = domNodesFromComponent(component);
  return domNodes
    .some(domNode => domNode.hasAttributeWithValue(attributeName, expectedValue))
}

const assertFunctions = {
  rendersDomNodeWithAttrAndValue(component, attributeName, expectedValue) {
    const found = rendersDomNodeWithAttrAndValue(component, attributeName, expectedValue);
    var message = `Expected \`${component.type.name || component.type}\` to render a DOM node with the attribute \`${attributeName}\` with value \`${expectedValue}\``;
    assert.ok(found, message);
  }
};

//rendersDomNodeAttributeWithValue
//rendersDomNodeWithInnerText

{'fraction_non_alphanumeric': 0.14826175869120656, 'fraction_numerical': 0.0, 'mean_word_length': 4.101694915254237, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2610519', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1109, 'n_words': 261}