From a7bf32156900325eff7ffb965bce016678b5161a Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 10 Oct 2019 11:03:11 +0200 Subject: [PATCH 1/2] fix(shouldExcludeFromA11yTree): Don't assume window contextg --- src/role-helpers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/role-helpers.js b/src/role-helpers.js index c7ff74c0..7948f4e2 100644 --- a/src/role-helpers.js +++ b/src/role-helpers.js @@ -15,6 +15,7 @@ const elementRoleList = buildElementRoleList(elementRoles) * @returns {boolean} true if excluded, otherwise false */ function shouldExcludeFromA11yTree(element) { + const window = element.ownerDocument.defaultView const computedStyle = window.getComputedStyle(element) // since visibility is inherited we can exit early if (computedStyle.visibility === 'hidden') { From 4bbbb4c290d4e77f11934b2a7f513c8bcdf291d7 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 10 Oct 2019 11:36:06 +0200 Subject: [PATCH 2/2] Add test --- src/__node_tests__/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/__node_tests__/index.js b/src/__node_tests__/index.js index fabe3534..d1b08a12 100644 --- a/src/__node_tests__/index.js +++ b/src/__node_tests__/index.js @@ -76,3 +76,23 @@ test('works without a browser context on a dom node (JSDOM Fragment)', () => { /> `) }) + +test('byRole works without a global DOM', () => { + const { + window: { + document: {body: container}, + }, + } = new JSDOM(` + + + + + + `) + + expect(dtl.getByRole(container, 'button')).toMatchInlineSnapshot(` + + `) +})