Skip to content

Commit 8110e86

Browse files
committed
test: use vaadin testing helpers
1 parent 0b4c6d3 commit 8110e86

File tree

6 files changed

+7
-72
lines changed

6 files changed

+7
-72
lines changed

packages/vaadin-date-time-picker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
"devDependencies": {
6767
"@esm-bundle/chai": "^4.1.5",
6868
"@open-wc/rollup-plugin-html": "^1.2.5",
69-
"@open-wc/testing-helpers": "^1.8.12",
7069
"@polymer/iron-component-page": "^4.0.0",
70+
"@vaadin/testing-helpers": "^0.1.0",
7171
"@web/dev-server": "^0.0.29",
7272
"@web/test-runner": "^0.10.0",
7373
"@web/test-runner-saucelabs": "^0.2.0",

packages/vaadin-date-time-picker/test/basic.test.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from '@esm-bundle/chai';
22
import sinon from 'sinon';
3-
import { aTimeout, nextFrame } from '@open-wc/testing-helpers';
4-
import { changeInputValue, fixtureSync } from './helpers.js';
3+
import { aTimeout, fixtureSync, nextFrame } from '@vaadin/testing-helpers';
4+
import { changeInputValue } from './helpers.js';
55
import '../vaadin-date-time-picker.js';
66

77
const fixtures = {
@@ -44,10 +44,6 @@ describe('Basic features', () => {
4444
timePicker = customField.inputs[1];
4545
});
4646

47-
afterEach(() => {
48-
dateTimePicker.remove();
49-
});
50-
5147
it('should not expose class name globally', () => {
5248
expect(window.DateTimePickerElement).not.to.be.ok;
5349
});
@@ -232,10 +228,6 @@ describe('autofocus', () => {
232228
await nextFrame();
233229
});
234230

235-
afterEach(() => {
236-
dateTimePicker.remove();
237-
});
238-
239231
it('should focus date picker when autofocus is set', () => {
240232
expect(datePicker.hasAttribute('focused')).to.be.true;
241233
});
@@ -250,10 +242,6 @@ describe('Initial value', () => {
250242
customField = dateTimePicker.$.customField;
251243
});
252244

253-
afterEach(() => {
254-
dateTimePicker.remove();
255-
});
256-
257245
it('should use initial value from attribute without clearing it', () => {
258246
expect(dateTimePicker.value).to.equal('2019-09-16T15:00');
259247
expect(customField.value).to.equal('2019-09-16T15:00');
@@ -267,10 +255,6 @@ describe('helperText', () => {
267255
dateTimePicker = fixtureSync('<vaadin-date-time-picker></vaadin-date-time-picker>');
268256
});
269257

270-
afterEach(() => {
271-
dateTimePicker.remove();
272-
});
273-
274258
it('should display the helper text when provided', () => {
275259
dateTimePicker.helperText = 'Foo';
276260
expect(dateTimePicker.$.customField.helperText).to.equal(dateTimePicker.helperText);
@@ -290,10 +274,6 @@ describe('slotted helper', () => {
290274
customField = dateTimePicker.$.customField;
291275
});
292276

293-
afterEach(() => {
294-
dateTimePicker.remove();
295-
});
296-
297277
it('should display the helper text when slotted helper available', () => {
298278
expect(customField.querySelector('[slot="helper"]').assignedNodes()[0].textContent).to.eql('foo');
299279
});
@@ -312,10 +292,6 @@ describe('Theme attribute', () => {
312292
timePicker = customField.inputs[1];
313293
});
314294

315-
afterEach(() => {
316-
dateTimePicker.remove();
317-
});
318-
319295
it('should propagate theme attribute to custom-field', () => {
320296
expect(customField.getAttribute('theme')).to.equal('foo');
321297
});
@@ -350,10 +326,6 @@ describe('Theme attribute', () => {
350326
}
351327
});
352328

353-
afterEach(() => {
354-
dateTimePicker.remove();
355-
});
356-
357329
it('should have correct inputs set in custom-field', () => {
358330
expect(customField.inputs[0]).to.equal(datePicker);
359331
expect(customField.inputs[1]).to.equal(timePicker);
@@ -436,10 +408,6 @@ describe('Theme attribute', () => {
436408
}
437409
});
438410

439-
afterEach(() => {
440-
dateTimePicker.remove();
441-
});
442-
443411
// This test simulates how DatePicker sets the initial value from server side
444412
it('should get initial value from slotted inputs', () => {
445413
expect(customField.value).to.equal('2019-09-16T15:00');

packages/vaadin-date-time-picker/test/helpers.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,3 @@ export const changeInputValue = (el, value) => {
44
el.value = value;
55
dispatchChange(el);
66
};
7-
8-
/**
9-
* Helper which mimics the way how Polymer <test-fixture> works.
10-
* Use `document.importNode` to ensure proper upgrade timings.
11-
*/
12-
export const fixtureSync = (html) => {
13-
const tpl = document.createElement('template');
14-
tpl.innerHTML = html;
15-
const div = document.createElement('div');
16-
div.appendChild(document.importNode(tpl.content, true));
17-
const el = div.firstElementChild;
18-
document.body.appendChild(el);
19-
return el;
20-
};

packages/vaadin-date-time-picker/test/i18n.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync } from './helpers.js';
2+
import { fixtureSync } from '@vaadin/testing-helpers';
33
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
44
import '../vaadin-date-time-picker.js';
55

@@ -105,10 +105,6 @@ customElements.define(
105105
}
106106
});
107107

108-
after(() => {
109-
dateTimePicker.remove();
110-
});
111-
112108
it('should have initial value for i18n', () => {
113109
expect(dateTimePicker.i18n).to.have.property('clear', 'Tyhjennä');
114110
expect(datePicker.i18n).to.have.property('clear', 'Tyhjennä');

packages/vaadin-date-time-picker/test/properties.test.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from '@esm-bundle/chai';
22
import sinon from 'sinon';
3-
import { dispatchChange, fixtureSync } from './helpers.js';
3+
import { fixtureSync } from '@vaadin/testing-helpers';
4+
import { dispatchChange } from './helpers.js';
45
import '../vaadin-date-time-picker.js';
56

67
const fixtures = {
@@ -78,10 +79,6 @@ const fixtures = {
7879
}
7980
});
8081

81-
afterEach(() => {
82-
dateTimePicker.remove();
83-
});
84-
8582
it('should propagate value to date and time pickers', () => {
8683
dateTimePicker.value = '2019-09-16T15:00';
8784
expect(datePicker.value).to.equal('2019-09-16');
@@ -308,10 +305,6 @@ const fixtures = {
308305
}
309306
});
310307

311-
after(() => {
312-
dateTimePicker.remove();
313-
});
314-
315308
it('should have initial value for errorMessage', () => {
316309
expect(dateTimePicker.errorMessage).to.equal('error-message');
317310
expect(customField.errorMessage).to.equal('error-message');

packages/vaadin-date-time-picker/test/validation.test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@esm-bundle/chai';
22
import sinon from 'sinon';
3-
import { fixtureSync } from './helpers.js';
3+
import { fixtureSync } from '@vaadin/testing-helpers';
44
import '../vaadin-date-time-picker.js';
55

66
class DateTimePicker2020Element extends customElements.get('vaadin-date-time-picker') {
@@ -31,10 +31,6 @@ const fixtures = {
3131
customField = dateTimePicker.$.customField;
3232
});
3333

34-
afterEach(() => {
35-
dateTimePicker.remove();
36-
});
37-
3834
it('should not be required', () => {
3935
expect(customField.required).to.be.false;
4036
});
@@ -110,10 +106,6 @@ describe('custom validator', () => {
110106
dateTimePicker = fixtureSync('<vaadin-date-time-picker-2020></vaadin-date-time-picker-2020>');
111107
});
112108

113-
afterEach(() => {
114-
dateTimePicker.remove();
115-
});
116-
117109
it('should validate correctly with custom validator', () => {
118110
// Try invalid value.
119111
dateTimePicker.value = '2030-03-03T20:30';

0 commit comments

Comments
 (0)