Skip to content

Commit

Permalink
test: make sure no initial validation happens (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
mukherjeesudebi authored Apr 17, 2023
1 parent d44eaa3 commit 3b4144c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
7 changes: 6 additions & 1 deletion test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"parserOptions": {
"ecmaVersion": 8
},
"rules": {
"no-undef": 0,
"no-unused-vars": 0
Expand All @@ -7,10 +10,12 @@
"WCT": false,
"describe": false,
"beforeEach": false,
"afterEach": false,
"fixture": false,
"it": false,
"expect": false,
"gemini": false,
"sinon": false
"sinon": false,
"nextRender": false
}
}
14 changes: 14 additions & 0 deletions test/helpers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>

<head>
<link rel="import" href="../../polymer/polymer.html">
</head>
<body>
<script>
window.nextRender = (element) => {
return new Promise(resolve => {
Polymer.RenderStatus.afterNextRender(element, resolve);
});
};
</script>
</body>
3 changes: 2 additions & 1 deletion test/test-suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ window.TimePickerElementSuites = [
'form-input.html',
'keyboard-navigation.html',
'styling.html',
'range-test.html'
'range-test.html',
'validation.html'
];
48 changes: 48 additions & 0 deletions test/validation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!doctype html>

<head>
<meta charset="UTF-8">
<title>vaadin-time-picker validation tests</title>
<script src='../../web-component-tester/browser.js'></script>
<script src='../../webcomponentsjs/webcomponents-lite.js'></script>
<link rel="import" href="../src/vaadin-time-picker.html">
<link rel="import" href="helpers.html">
</head>

<body>
<script>
describe('initial validation', () => {
let timePicker, validateSpy;

beforeEach(() => {
timePicker = document.createElement('vaadin-time-picker');
validateSpy = sinon.spy(timePicker, 'validate');
});

afterEach(() => {
timePicker.remove();
});

it('should not validate by default', async() => {
document.body.appendChild(timePicker);
await nextRender();
expect(validateSpy.called).to.be.false;
});

it('should not validate when the field has an initial value', async() => {
timePicker.value = '12:00';
document.body.appendChild(timePicker);
await nextRender();
expect(validateSpy.called).to.be.false;
});

it('should not validate when the field has an initial value and invalid', async() => {
timePicker.value = '12:00';
timePicker.invalid = true;
document.body.appendChild(timePicker);
await nextRender();
expect(validateSpy.called).to.be.false;
});
});
</script>
</body>

0 comments on commit 3b4144c

Please sign in to comment.