Skip to content

axe.setup should set globals #3962

@WilcoFiers

Description

@WilcoFiers

Axe-core's setup and teardown methods should be able to work with JSDOM:

import axe from 'axe-core'
import { JSDOM } from 'jsdom'
const { window } = new JSDOM(`<!DOCTYPE html>\n<html></html>`);
axe.setup(window)

Currently the only way to use axe.setup() with JSDOM is if globalThis.window and globalThis.document are defined before axe-core is imported. This is annoying and shouldn't be necessary. We handle this in axe.run() by calling setupGlobals. Probably this call should just be moved into axe.setup(), and the resetGlobals() call should go into axe.teardown().

Another problem I'm spotting is that axe.runPartial() doesn't set up globals either. Moving these calls to setup/teardown will solve that too. A test for this would be useful.

Metadata

Metadata

Assignees

Labels

coreIssues in the core code (lib/core)fixBug fixes

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions