Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Integration testing with jsdom #50

Open
avh4 opened this issue Jun 7, 2014 · 3 comments
Open

Integration testing with jsdom #50

avh4 opened this issue Jun 7, 2014 · 3 comments
Labels

Comments

@avh4
Copy link

avh4 commented Jun 7, 2014

Following this discussion #45 (comment) which led to a solution with min-document, here is a minimal repro example with jsdom. The event does not get fired.

var jsdom = require('jsdom').jsdom;
var mercury = require('mercury');
var h = mercury.h;
var event = require('synthetic-dom-events');

var callCount = 0;

var click = mercury.input();
click(function() { callCount++; });
function render(onClick) {
  return h('button', {'ev-click': mercury.event(onClick)}, 'Click Me');
};

describe('integration tests', function() {
  var document, $;

  beforeEach(function(done) {
    var doc = jsdom('<html><body></body></html>');
    var window = doc.parentWindow;
    document = window.document;
    jsdom.jQueryify(doc.parentWindow, "../node_modules/jquery/dist/jquery.js", function() {
      $ = window.$;
      done();
    });
  });

  describe('clicking the button', function() {
    beforeEach(function(done) {
      var div = document.createElement('div');
      mercury.app(div, mercury.value(click), render, {document: document});
      document.body.appendChild(div);
      $('button').click();
      // Also tried $('button').trigger('click');
      setTimeout(done);
    });

    it('increments the counter', function() {
      expect(callCount).to.equal(1);
    });    
  });
});
@avh4
Copy link
Author

avh4 commented Jun 7, 2014

The handler fn in dom-delegator is never getting called, so it seems like either the jquery click()/trigger() are not causing the right events for the delegator to pick up, or the delegator is not initialized correctly.

@kumavis
Copy link
Collaborator

kumavis commented Feb 5, 2015

If this is the entire code, it seems that a Dom-Delegator is never being instantiated.

@Raynos
Copy link
Owner

Raynos commented Feb 5, 2015

hg.app() creates a delegator for you.

This is mostly an issue about testing with min-document vs jsdom. We've only verified min-document.

@kumavis kumavis added the bug label Feb 5, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants