|
2 | 2 | * @license |
3 | 3 | * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE) |
4 | 4 | */ |
5 | | -/* global describe, it, before, after, beforeEach, afterEach, expect, Browser, pryv, Blob, FormData */ |
| 5 | +/* global describe, it, before, after, beforeEach, afterEach, expect, JSDOM, pryv, Blob, FormData */ |
6 | 6 | /* eslint-disable no-unused-expressions */ |
7 | 7 |
|
8 | 8 | // URL and URLSearchParams are native in Node.js and browsers |
@@ -382,35 +382,19 @@ describe('Connection', () => { |
382 | 382 |
|
383 | 383 | if (typeof window === 'undefined') { |
384 | 384 | describe('Browser mock', function () { |
385 | | - const isNotAvailable = { |
386 | | - URL: global.URL == null, |
387 | | - URLSearchParams: global.URLSearchParams == null, |
388 | | - fetch: global.fetch == null |
389 | | - }; |
390 | 385 | beforeEach(function () { |
391 | | - const browser = new Browser(); |
392 | | - browser.visit('./'); |
393 | | - global.document = browser.document; |
394 | | - global.window = browser.window; |
395 | | - global.location = browser.location; |
396 | | - function fetch (...args) { |
397 | | - return browser.fetch(...args); |
398 | | - } |
399 | | - if (isNotAvailable.fetch) global.fetch = fetch; |
400 | | - if (isNotAvailable.URL) global.URL = URL; |
401 | | - if (isNotAvailable.URLSearchParams) global.URLSearchParams = URLSearchParams; |
| 386 | + const dom = new JSDOM('<!DOCTYPE html>', { url: 'http://localhost/' }); |
| 387 | + global.document = dom.window.document; |
| 388 | + global.window = dom.window; |
| 389 | + global.location = dom.window.location; |
402 | 390 | }); |
403 | 391 |
|
404 | 392 | afterEach(function () { |
405 | 393 | delete global.document; |
406 | 394 | delete global.window; |
407 | 395 | delete global.location; |
408 | | - if (isNotAvailable.fetch) delete global.fetch; |
409 | | - if (isNotAvailable.URL) delete global.URL; |
410 | | - if (isNotAvailable.URLSearchParams) delete global.URLSearchParams; |
411 | 396 | }); |
412 | 397 |
|
413 | | - // HACK: skip until a solution is found to Zombie's `fetch()` not accepting URLs |
414 | 398 | it(' with fetch', async () => { |
415 | 399 | const queryParams = { fromTime: 0, toTime: now, limit: 10000 }; |
416 | 400 | let eventsCount = 0; |
|
0 commit comments