rstacruz / mocha-jsdom

Simple jsdom integration with mocha

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jquery requires a window with document?????

kokokele opened this issue · comments

code:

var chai = require('chai')
var jsdom = require('mocha-jsdom')

var expect = chai.expect;

describe('jquery', function () {
  var $
  jsdom()

  before(function () {
    $ = require('jquery')
  })

  it('creating elements works', function () {
    var div = $('<div>hello <b>world</b></div>')
    expect(div.html()).to.eql('hello <b>world</b>')
  })

  it('lookup works', function () {
    document.body.innerHTML = '<div>hola</div>'
    expect($('div').html()).eql('hola')
  })
})

test out :

jquery
    1) creating elements works
    2) lookup works


  0 passing (789ms)
  2 failing

  1) jquery creating elements works:
     Error: jQuery requires a window with a document
      at module.exports (node_modules/jquery/dist/jquery.js:29:12)

      at Context.<anonymous> (test.js:17:15)

  2) jquery lookup works:
     Error: jQuery requires a window with a document
      at module.exports (node_modules/jquery/dist/jquery.js:29:12)
      at Context.<anonymous> (test.js:23:12)

I'm getting the same issue. How did you fix it?

Can you try with github.com/rstacruz/jsdom-global?

On Wed, Aug 10, 2016, 6:50 AM Robert Misiorowski notifications@github.com
wrote:

I'm getting the same issue. How did you fix it?


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub
#20 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEikVH2GMf2Gxj4oSTFePcBGKsymRJxks5qeQQygaJpZM4H02BI
.

I get the same error. Here's the code I'm using:

import 'jsdom-global/register';
import $ from 'jquery';
import { expect } from 'chai';
import { describe, it } from 'mocha';

describe('jquery', function () {
  it('creating elements works', function () {
    const div = $('<div>hello <b>world</b></div>');
    expect(div.html()).to.eql('hello <b>world</b>');
  });
});