Skip to content

Commit e84f612

Browse files
correct test to test paste on dispatch keydown event
1 parent fea55a6 commit e84f612

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

test/test.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ describe('paste-markdown', function () {
3131
assert.equal(textarea.value, 'The examples can be found [here](https://github.com).')
3232
})
3333

34-
it('does not turn pasted urls on selected text into markdown links if skip formatting', function () {
35-
// eslint-disable-next-line i18n-text/no-en
36-
textarea.value = 'The examples can be found here.'
37-
textarea.addEventListener('keydown', skipFormatting(textarea))
38-
textarea.setSelectionRange(26, 30)
39-
paste(textarea, {'text/plain': 'https://github.com'})
40-
assert.equal(textarea.value, 'The examples can be found here.')
41-
})
42-
4334
it("doesn't paste a markdown URL when pasting over a selected URL", function () {
4435
// eslint-disable-next-line i18n-text/no-en
4536
textarea.value = 'The examples can be found here: https://docs.github.com'
@@ -222,10 +213,30 @@ describe('paste-markdown', function () {
222213
paste(textarea, {'text/html': sentence, 'text/plain': plaintextSentence})
223214
assert.equal(textarea.value, markdownSentence)
224215
})
216+
217+
// Note: It's possible to construct and dispatch a synthetic paste event,
218+
// but this will not affect the document's contents in tests to assert it.
219+
// So for that reason assert result on keydown (Ctrl+Shift+v) will be empty '' here.
220+
it('when dispatch keydown event (Ctrl+Shift+v) to skip formatting', function () {
221+
const data = {
222+
'text/html': `
223+
<table data-paste-markdown-skip>
224+
<thead><tr><th>name</th><th>origin</th></tr></thead>
225+
<tbody>
226+
<tr><td>hubot</td><td>github</td></tr>
227+
<tr><td>bender</td><td>futurama</td></tr>
228+
</tbody>
229+
</table>
230+
`
231+
}
232+
textarea.addEventListener('keydown', dispatchSkipFormattingKeyEvent(textarea))
233+
paste(textarea, data)
234+
assert.equal(textarea.value, '')
235+
})
225236
})
226237
})
227238

228-
function skipFormatting(textarea) {
239+
function dispatchSkipFormattingKeyEvent(textarea) {
229240
textarea.dispatchEvent(
230241
new KeyboardEvent('keydown', {
231242
key: 'v',

0 commit comments

Comments
 (0)