UNPKG

1.55 kBJavaScriptView Raw
1'use strict';
2
3var assert = require('assert');
4var validateOptions = require('./validate-options').default;
5var schema = require('./schema').default;
6
7describe('Validate options', function () {
8 it('fails without a schema and data', function () {
9 assert.throws(function () {
10 validateOptions();
11 }, Error);
12 });
13
14 it('fails with empty data', function () {
15 var result = validateOptions(schema());
16
17 assert.ok(!result.isValid);
18 assert.ok(result.error);
19 });
20
21 it('does not fail if paths are provided', function () {
22 var result = validateOptions(schema(), { paths: ['./foo'] });
23
24 assert.ok(result.isValid);
25 assert.ok(!result.error);
26 });
27
28 it('does not allow arbitrary properties', function () {
29 var result = validateOptions(schema(), { paths: ['./foo'], foobar: ['./foo'] });
30
31 assert.ok(!result.isValid);
32 assert.ok(result.error);
33 });
34
35 it('styleExtensions have defaults', function () {
36 var paths = ['./foo'];
37 var data = { paths: paths };
38
39 // Currently this mutates data with defaults due to ajv design. It
40 // might be a good idea to change that behavior, though.
41 var result = validateOptions(schema(), data);
42
43 assert.deepEqual(data, { paths: paths, styleExtensions: ['.css'] });
44 assert.ok(!result.error);
45 });
46
47 it('fails without matching path keys', function () {
48 var data = {
49 paths: {
50 a: './foo'
51 }
52 };
53
54 var result = validateOptions(schema({
55 entry: {
56 b: './bar'
57 }
58 }), data);
59
60 assert.ok(result.error);
61 });
62});
\No newline at end of file