Skip to content

Commit

Permalink
test: make sure no initial validation happens (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
mukherjeesudebi authored Apr 17, 2023
1 parent eb42fc5 commit 9d724c2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
6 changes: 5 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-unused-vars": 0
},
Expand Down Expand Up @@ -34,6 +37,7 @@
"_fixture": false,
"gemini": false,
"flush": false,
"ShadyDOM": false
"ShadyDOM": 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 @@ -17,7 +17,8 @@ window.VaadinComboBoxSuites = [
'item-renderer.html',
'item-template.html',
'vaadin-combo-box-dropdown.html',
'lazy-loading.html'
'lazy-loading.html',
'validation.html'
];

if (isPolymer2) {
Expand Down
55 changes: 55 additions & 0 deletions test/validation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!doctype html>
<html>

<head>
<meta charset="UTF-8">
<title>vaadin-combo-box validation tests</title>

<script src="../../web-component-tester/browser.js"></script>
<script src='../../webcomponentsjs/webcomponents-lite.js'></script>
<link rel="import" href="../src/vaadin-combo-box.html">
<link rel="import" href="helpers.html">
</head>

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

beforeEach(() => {
comboBox = document.createElement('vaadin-combo-box');
comboBox.allowCustomValue = true;
validateSpy = sinon.spy(comboBox, 'validate');
});

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

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

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

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

</body>

</html>

0 comments on commit 9d724c2

Please sign in to comment.