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.
Axe-core's setup and teardown methods should be able to work with JSDOM:
Currently the only way to use
axe.setup()with JSDOM is ifglobalThis.windowandglobalThis.documentare defined before axe-core is imported. This is annoying and shouldn't be necessary. We handle this inaxe.run()by callingsetupGlobals. Probably this call should just be moved intoaxe.setup(), and theresetGlobals()call should go intoaxe.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.