-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathFormValueFile.test.ts
More file actions
49 lines (38 loc) · 1.35 KB
/
FormValueFile.test.ts
File metadata and controls
49 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { expect, fixture, fixtureCleanup, html } from '@open-wc/testing';
import '../dist/index.js';
class TestFileUpload extends HTMLElement {
static formAssociated = true;
internals = this.attachInternals();
}
customElements.define('test-file-upload', TestFileUpload);
async function createForm(): Promise<HTMLFormElement> {
return await fixture<HTMLFormElement>(html`
<form id="form">
<test-file-upload name="foo" id="foo"></test-file-upload>
<button type="submit">Submit</button>
</form>`);
}
describe('setFormValue polyfill with File type', () => {
let form, el, file;
beforeEach(async () => {
form = await createForm();
el = form.querySelector('#foo') as TestFileUpload;
file = new File(['foo'], 'foo.txt', { type: 'text/plain' });
});
afterEach(async () => {
await fixtureCleanup();
});
it('must submit a file', async () => {
el.internals.setFormValue(file);
const result = new FormData(form);
expect(result.get('foo')).to.equal(file);
});
it('must submit multiple files through FormData', async () => {
const formData = new FormData();
formData.append('foo', file);
formData.append('foo', file); // append the same file twice
el.internals.setFormValue(formData);
const result = new FormData(form);
expect(result.getAll('foo')).to.deep.equal([file, file]);
});
});