From 70cbd4b4b364a45cf07da93b2487d77652de3c7e Mon Sep 17 00:00:00 2001 From: Juho Vepsalainen Date: Sat, 28 Jan 2017 18:29:46 +0200 Subject: [PATCH] fix(schema): emit proper error messages Related to #371. --- schema/validator.js | 6 +++--- test/extract.test.js | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/schema/validator.js b/schema/validator.js index b5811dc2..fa6244ff 100644 --- a/schema/validator.js +++ b/schema/validator.js @@ -3,10 +3,10 @@ var ajv = new Ajv({allErrors: true}); var json = require('./schema.json'); module.exports = function validate(data) { - var validSchema = ajv.compile(json); - var valid = validSchema(data); + var ajv = new Ajv(); + var isValid = ajv.validate(json, data); - if(!valid) { + if(!isValid) { throw new Error(ajv.errorsText()); } } diff --git a/test/extract.test.js b/test/extract.test.js index b4e93b2d..fe1fdf91 100644 --- a/test/extract.test.js +++ b/test/extract.test.js @@ -24,9 +24,14 @@ describe("ExtractTextPlugin.extract()", function() { }); it("throws if an incorrect config is passed in", function() { - should.throws(function() { - ExtractTextPlugin.extract({style: 'file.css'}); - }); + should.throws( + function() { + ExtractTextPlugin.extract({style: 'file.css'}); + }, + function(err) { + return err.message === 'data should NOT have additional properties'; + } + ); }); });