Skip to content

Commit 49ad6f4

Browse files
committed
refactor: Test bed methods
1 parent 12c2ce9 commit 49ad6f4

File tree

4 files changed

+13
-38
lines changed

4 files changed

+13
-38
lines changed

src/components/combo/combo.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,10 +1359,10 @@ describe('Combo', () => {
13591359

13601360
it('fulfils custom constraint', () => {
13611361
spec.element.setCustomValidity('invalid');
1362-
spec.submitFails();
1362+
spec.assertSubmitFails();
13631363

13641364
spec.element.setCustomValidity('');
1365-
spec.submitValidates();
1365+
spec.assertSubmitPasses();
13661366
});
13671367
});
13681368

src/components/common/utils.spec.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,10 @@ export class FormAssociatedTestBed<T extends IgcFormControl> {
7575

7676
/**
7777
* Attempts to submit the form element.
78-
* If constraint validation passes returns the form data, otherwise `undefined`.
78+
* If constraint validation passes returns the form data, otherwise returns a
79+
* default `initialFormData` sentinel value.
7980
*/
80-
public submit(): FormData | undefined {
81-
let data!: FormData;
82-
83-
this.form.addEventListener(
84-
'submit',
85-
(e) => {
86-
e.preventDefault();
87-
data = new FormData(this.form);
88-
},
89-
{ once: true }
90-
);
91-
this.form.requestSubmit();
92-
return data;
93-
}
94-
95-
// REVIEW: Delete the original submit and rename this after migrating the test beds
96-
public submitV2(): FormData {
81+
public submit(): FormData {
9782
let data = initialFormData;
9883

9984
// let data = new FormData();
@@ -151,23 +136,23 @@ export class FormAssociatedTestBed<T extends IgcFormControl> {
151136
* in its form data.
152137
*/
153138
public assertSubmitHasValue(value: unknown, msg?: string): void {
154-
expect(this.submitV2().get(this.element.name), msg).to.eql(value);
139+
expect(this.submit().get(this.element.name), msg).to.eql(value);
155140
}
156141

157142
/**
158143
* Whether the form is submitted and contains the given 'value'
159144
* in its form data.
160145
*/
161146
public assertSubmitHasValues(value: unknown, msg?: string): void {
162-
expect(this.submitV2().getAll(this.element.name), msg).to.eql(value);
147+
expect(this.submit().getAll(this.element.name), msg).to.eql(value);
163148
}
164149

165150
/**
166151
* Whether the form fails to submit.
167152
* The component will be in invalid state and the form data will be empty.
168153
*/
169154
public assertSubmitFails(msg?: string): void {
170-
expect(this.submitV2() === initialFormData, msg).to.be.true;
155+
expect(this.submit() === initialFormData, msg).to.be.true;
171156
expect(this.valid, msg).to.be.false;
172157
}
173158

@@ -177,20 +162,10 @@ export class FormAssociatedTestBed<T extends IgcFormControl> {
177162
* component name and value.
178163
*/
179164
public assertSubmitPasses(msg?: string): void {
180-
expect(this.submitV2() === initialFormData, msg).to.be.false;
165+
expect(this.submit() === initialFormData, msg).to.be.false;
181166
expect(this.valid, msg).to.be.true;
182167
}
183168

184-
public submitValidates(msg?: string): void {
185-
expect(this.submit(), msg).not.to.be.undefined;
186-
expect(this.valid, msg).to.be.true;
187-
}
188-
189-
public submitFails(msg?: string): void {
190-
expect(this.submit(), msg).to.be.undefined;
191-
expect(this.valid, msg).to.be.false;
192-
}
193-
194169
/**
195170
* Whether the form element is in 'pristine' state.
196171
*/

src/components/date-time-input/date-time-input.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,10 +977,10 @@ describe('Date Time Input component', () => {
977977

978978
it('fulfils custom constraint', () => {
979979
spec.element.setCustomValidity('invalid');
980-
spec.submitFails();
980+
spec.assertSubmitFails();
981981

982982
spec.element.setCustomValidity('');
983-
spec.submitValidates();
983+
spec.assertSubmitPasses();
984984
});
985985
});
986986

src/components/input/input.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,10 @@ describe('Input component', () => {
469469

470470
it('fulfils custom constraint', () => {
471471
spec.element.setCustomValidity('invalid');
472-
spec.submitFails();
472+
spec.assertSubmitFails();
473473

474474
spec.element.setCustomValidity('');
475-
spec.submitValidates();
475+
spec.assertSubmitPasses();
476476
});
477477

478478
it('validates schema types - email', () => {

0 commit comments

Comments
 (0)