Skip to content

Commit

Permalink
Validator should not throw an exception if the instance was destroyed…
Browse files Browse the repository at this point in the history
… in the meantime. #5567
  • Loading branch information
mrpiotr-dev committed Jan 3, 2019
1 parent 2093d85 commit c356a59
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/core.js
Expand Up @@ -1063,23 +1063,27 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
value = instance.runHooks('beforeValidate', value, cellProperties.visualRow, cellProperties.prop, source);

// To provide consistent behaviour, validation should be always asynchronous
instance._registerTimeout(setTimeout(() => {
instance._registerImmediate(() => {
console.log('validateCell._registerImmediate');
validator.call(cellProperties, value, (valid) => {
if (!instance) {
return false;
}
// eslint-disable-next-line no-param-reassign
valid = instance.runHooks('afterValidate', valid, value, cellProperties.visualRow, cellProperties.prop, source);
cellProperties.valid = valid;

done(valid);
instance.runHooks('postAfterValidate', valid, value, cellProperties.visualRow, cellProperties.prop, source);
});
}, 0));
});

} else {
// resolve callback even if validator function was not found
instance._registerTimeout(setTimeout(() => {
instance._registerImmediate(() => {
cellProperties.valid = true;
done(cellProperties.valid, false);
}, 0));
});
}
};

Expand Down
11 changes: 5 additions & 6 deletions test/e2e/Core_validate.spec.js
Expand Up @@ -1295,7 +1295,7 @@ describe('Core_validate', () => {
}, 200);
});

it('should remove htInvalid class properly after cancelling change, when physical indexes are not equal to visual indexes', (done) => {
it('should remove htInvalid class properly after cancelling change, when physical indexes are not equal to visual indexes', async() => {
handsontable({
data: Handsontable.helper.createSpreadsheetData(5, 2),
columnSorting: {
Expand All @@ -1317,11 +1317,10 @@ describe('Core_validate', () => {

keyDown('enter');

setTimeout(() => {
const $cell = $(getCell(0, 0));
expect($cell.hasClass('htInvalid')).toEqual(false);
done();
}, 200);
await sleep(300);

const $cell = $(getCell(0, 0));
expect($cell.hasClass('htInvalid')).toEqual(false);
});

it('should not attempt to remove the htInvalid class if the validated cell is no longer rendered', (done) => {
Expand Down

0 comments on commit c356a59

Please sign in to comment.