remove use of global in test

This commit is contained in:
Daniel Waxweiler 2021-05-03 21:39:23 +02:00
parent bfa6c00e45
commit 74522103a2
3 changed files with 7 additions and 5 deletions

View File

@ -11,7 +11,7 @@ function displayEvents(data, list) {
for (let i = 0; i < eventsCount; i++) {
const li = document.createElement('li')
const a = createAnchorElement({ text: events[i].title, url: events[i].url })
const a = createAnchorElement({ document, text: events[i].title, url: events[i].url })
li.appendChild(a)
const br = document.createElement('br')

View File

@ -1,14 +1,16 @@
import test from 'ava'
import { JSDOM } from 'jsdom'
import * as HtmlCreator from './html-creator'
import { createAnchorElement } from './html-creator'
let document
test.beforeEach(() => {
global.document = new JSDOM().window.document
document = new JSDOM().window.document
})
test('#createAnchorElement usual parameters', t => {
const a = HtmlCreator.createAnchorElement({ text: 'a', url: 'b' })
const a = createAnchorElement({ document, text: 'a', url: 'b' })
t.is(a.tagName, 'A')
t.is(a.innerHTML, 'a')
t.is(a.getAttribute('href'), 'b')

View File

@ -1,4 +1,4 @@
export function createAnchorElement({ text, url }) {
export function createAnchorElement({ document, text, url }) {
const a = document.createElement('a')
a.setAttribute('href', url)
a.setAttribute('target', '_blank')