@lion/validate
Advanced tools
Comparing version 0.6.5 to 0.6.6
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.6.6](https://github.com/ing-bank/lion/compare/@lion/validate@0.6.5...@lion/validate@0.6.6) (2020-02-06) | ||
### Bug Fixes | ||
* **validator:** throw error if getMessage not of type Function ([ce3c02b](https://github.com/ing-bank/lion/commit/ce3c02b63bf8bc807946457c1a9289b8b57b5ee2)) | ||
## [0.6.5](https://github.com/ing-bank/lion/compare/@lion/validate@0.6.4...@lion/validate@0.6.5) (2020-02-03) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@lion/validate", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"description": "Validate your form elements", | ||
@@ -37,4 +37,4 @@ "author": "ing-bank", | ||
"dependencies": { | ||
"@lion/core": "0.4.2", | ||
"@lion/localize": "0.8.5" | ||
"@lion/core": "0.4.3", | ||
"@lion/localize": "0.8.6" | ||
}, | ||
@@ -46,3 +46,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "30a8197f18bf1f27fc41f392bde517a5fb94cbcd" | ||
"gitHead": "d67225984ce359c421e1c1e350da98819f83e452" | ||
} |
@@ -61,4 +61,10 @@ import { fakeExtendsEventTarget } from './utils/fake-extends-event-target.js'; | ||
}; | ||
if (typeof this.config.getMessage === 'function') { | ||
return this.config.getMessage(composedData); | ||
if (this.config.getMessage) { | ||
if (typeof this.config.getMessage === 'function') { | ||
return this.config.getMessage(composedData); | ||
} | ||
throw new Error( | ||
`You must provide a value for getMessage of type 'function', you provided a value of type: ${typeof this | ||
.config.getMessage}`, | ||
); | ||
} | ||
@@ -65,0 +71,0 @@ return this.constructor.getMessage(composedData); |
import { expect, fixture, html, unsafeStatic, defineCE } from '@open-wc/testing'; | ||
import sinon from 'sinon'; | ||
import { LitElement } from '@lion/core'; | ||
import sinon from 'sinon'; | ||
import { ValidateMixin } from '../src/ValidateMixin.js'; | ||
import { Validator } from '../src/Validator.js'; | ||
async function expectThrowsAsync(method, errorMessage) { | ||
let error = null; | ||
try { | ||
await method(); | ||
} catch (err) { | ||
error = err; | ||
} | ||
expect(error).to.be.an('Error', 'No error was thrown'); | ||
if (errorMessage) { | ||
expect(error.message).to.equal(errorMessage); | ||
} | ||
} | ||
describe('Validator', () => { | ||
@@ -25,2 +38,16 @@ it('has an "execute" function returning "shown" state', async () => { | ||
it('throws when executing a Validator that has a getMessage config property with a value not of type function', async () => { | ||
class MyValidator extends Validator { | ||
constructor(...args) { | ||
super(...args); | ||
this.name = 'MyValidator'; | ||
} | ||
} | ||
await expectThrowsAsync( | ||
() => new MyValidator({}, { getMessage: 'This is the custom error message' })._getMessage(), | ||
"You must provide a value for getMessage of type 'function', you provided a value of type: string", | ||
); | ||
}); | ||
it('receives a "param" as a first argument on instantiation', async () => { | ||
@@ -27,0 +54,0 @@ const vali = new Validator('myParam'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
208565
4411
+ Added@lion/core@0.4.3(transitive)
+ Added@lion/localize@0.8.6(transitive)
+ Addedlit-element@2.5.1(transitive)
- Removed@lion/localize@0.8.5(transitive)
Updated@lion/core@0.4.3
Updated@lion/localize@0.8.6