Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 740d160

Browse files
authored
Merge pull request NightlyCommit#8 from ericmorand/issue_7
Fix issue NightlyCommit#7
2 parents baa133a + d4bbf0b commit 740d160

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const optionsSchema = {
2020
},
2121
required: [
2222
'environmentModulePath'
23-
]
23+
],
24+
additionalProperties: false
2425
};
2526

2627
class PathSupportingArrayLoader extends TwingLoaderArray {

test/unit/index/test.ts

+76
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,81 @@ tape('loader', (test: Test) => {
4949
test.end();
5050
});
5151

52+
test.test('provides options validation', (test) => {
53+
type ValidationError = {
54+
dataPath: string,
55+
keyword: string,
56+
message: string
57+
};
58+
59+
type Fixture = {
60+
options: any,
61+
expectation: ValidationError
62+
};
63+
64+
let fixtures: Fixture[] = [
65+
{
66+
options: {},
67+
expectation: {
68+
dataPath: '',
69+
keyword: 'required',
70+
message: 'should have required property \'environmentModulePath\''
71+
}
72+
},
73+
{
74+
options: {
75+
environmentModulePath: {}
76+
},
77+
expectation: {
78+
dataPath: '.environmentModulePath',
79+
keyword: 'type',
80+
message: 'should be string'
81+
}
82+
},
83+
{
84+
options: {
85+
environmentModulePath: '',
86+
renderContext: ''
87+
},
88+
expectation: {
89+
dataPath: '.renderContext',
90+
keyword: 'type',
91+
message: 'should be object'
92+
}
93+
},
94+
{
95+
options: {
96+
environmentModulePath: '',
97+
foo: ''
98+
},
99+
expectation: {
100+
dataPath: '',
101+
keyword: 'additionalProperties',
102+
message: 'should NOT have additional properties'
103+
}
104+
}
105+
];
106+
107+
for (let fixture of fixtures) {
108+
let errors: ValidationError[];
109+
110+
try {
111+
loader.bind({
112+
query: fixture.options
113+
})();
114+
115+
errors = [];
116+
} catch (e) {
117+
errors = e.errors;
118+
}
119+
120+
test.same(errors[0].dataPath, fixture.expectation.dataPath);
121+
test.same(errors[0].keyword, fixture.expectation.keyword);
122+
test.same(errors[0].message, fixture.expectation.message);
123+
}
124+
125+
test.end();
126+
});
127+
52128
test.end();
53129
});

0 commit comments

Comments
 (0)