JSFiddle - React, Tailwind, and code Playground

JSFiddle ~1 min read
View original
Crawl details
  • best

This article is too short to summarise.

HTML

<script src="https://code.jquery.com/qunit/qunit-2.3.2.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.3.2.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

CSS

.modal {
  display: none;
}

.active {
  display: block;
}

JavaScript

QUnit.test('the modal is NOT open by default', (assert) => {
  // Arrange (compile)
  // Act (to open by default when compiled)
  const compiledModal = compileComponent('<modal></modal>');

  // Assert (that is open)
  const actual = compiledModal.find('.modal').is(':visible');
  const expected = false;
  assert.strictEqual(actual, expected, 'Modal should be visible in the screen');
});

QUnit.test('the modal can close', (assert) => {
  // Arrange (compile)
  const compiledModal = compileComponent('<modal></modal>');

  // Act (to close the modal)
  $('.modal').find('.close').click();

  // Assert (that is closed)
  const actual = compiledModal.find('.modal').is(':visible');
  const expected = false;
  assert.strictEqual(
    actual,
    expected,
    'Modal should NOT be visible in the screen'
  );
});

function compileComponent(template) {
  const component = $(template);
  component.html(`
    <div class="modal">
      <h1>My Modal</h1>
    </div>
  `);
  return component.appendTo('#qunit-fixture');
}