-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: call stack error in jsdom when clicking label element descendants
- Loading branch information
Showing
2 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const request = require('supertest'); | ||
const nock = require('nock'); | ||
|
||
const { app } = require('../../../build/app'); | ||
const { createSession } = require('./helpers'); | ||
const { ELEMENT } = require('../../../build/constants/constants'); | ||
|
||
describe('Click Element', () => { | ||
let sessionId; | ||
|
||
beforeAll(async () => { | ||
nock(/plumadriver\.com/) | ||
.get('/') | ||
.reply( | ||
200, | ||
`<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Test Page</title> | ||
</head> | ||
<body> | ||
<label> | ||
<select> | ||
<option id="overflow-option" value="foo"></option> | ||
</select> | ||
</label> | ||
<label> | ||
<textarea id="overflow-textarea"></textarea> | ||
</label> | ||
<div id="bar" onclick=""> | ||
<button id="bubble">bubbled=false</button> | ||
</div> | ||
<script> | ||
document | ||
.querySelector('#bar') | ||
.addEventListener( | ||
'click', | ||
e => (e.target.textContent = 'bubbled=true'), | ||
); | ||
</script> | ||
</body> | ||
</html> | ||
`, | ||
); | ||
|
||
sessionId = await createSession(request, app); | ||
await request(app) | ||
.post(`/session/${sessionId}/url`) | ||
.send({ | ||
url: 'http://plumadriver.com', | ||
}); | ||
}); | ||
|
||
const getElement = async cssSelector => { | ||
const { | ||
body: { | ||
value: { [ELEMENT]: elementId }, | ||
}, | ||
} = await request(app) | ||
.post(`/session/${sessionId}/element`) | ||
.send({ using: 'css selector', value: cssSelector }) | ||
.expect(200); | ||
|
||
return elementId; | ||
}; | ||
|
||
const clickElement = elementId => { | ||
return request(app) | ||
.post(`/session/${sessionId}/element/${elementId}/click`) | ||
.expect(200); | ||
}; | ||
|
||
it('does not cause call stack error when clicking label descendant', async () => { | ||
const optionElementId = await getElement('#overflow-option'); | ||
await clickElement(optionElementId); | ||
|
||
const textareaElementId = await getElement('#overflow-textarea'); | ||
await clickElement(textareaElementId); | ||
}); | ||
|
||
it('bubbles click events', async () => { | ||
const buttonElementId = await getElement('#bubble'); | ||
await clickElement(buttonElementId); | ||
|
||
const { | ||
body: { value }, | ||
} = await request(app).get( | ||
`/session/${sessionId}/element/${buttonElementId}/text`, | ||
); | ||
|
||
expect(value).toBe('bubbled=true'); | ||
}); | ||
}); |