Skip to content

Commit 1e0ebae

Browse files
committed
fix(validate): honor _opts: { validation: { logErrors: true }}
1 parent ab87ad3 commit 1e0ebae

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/lib/moduleExec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export default async function moduleExec(this: ThisWithFetch, opts: ModuleExecOp
146146
* database, etc. Otherwise you'll receive an error.
147147
*/
148148
try {
149-
validateAndCoerceTypes(result, opts.result.schemaKey, undefined, this._options?.validation);
149+
validateAndCoerceTypes(result, opts.result.schemaKey, undefined, this._opts?.validation);
150150
} catch (error) {
151151
if (!moduleOpts || moduleOpts.validateResult === undefined || moduleOpts.validateResult === true)
152152
throw error;

src/lib/validateAndCoerceTypes.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('validateAndCoerceTypes', () => {
7676
/* @ts-ignore */
7777
result.price.postMarketChangePercent = true;
7878
expect(
79-
() => validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY)
79+
() => validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY, undefined, defaultOptions)
8080
).toThrow(/Failed Yahoo Schema/);
8181
});
8282

@@ -86,7 +86,7 @@ describe('validateAndCoerceTypes', () => {
8686
/* @ts-ignore */
8787
result.price.postMarketChangePercent = { raw: "a string" };
8888
expect(
89-
() => validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY)
89+
() => validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY, undefined, defaultOptions)
9090
).toThrow(/Failed Yahoo Schema/);
9191
});
9292

@@ -131,7 +131,7 @@ describe('validateAndCoerceTypes', () => {
131131
/* @ts-ignore */
132132
result.price.postMarketTime = "clearly not a date";
133133
expect(
134-
() => validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY)
134+
() => validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY, undefined, defaultOptions)
135135
).toThrow(/Failed Yahoo Schema/);
136136
});
137137

@@ -164,7 +164,7 @@ describe('validateAndCoerceTypes', () => {
164164

165165
let error: FailedYahooValidationError;
166166
try {
167-
validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY)
167+
validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY, undefined, defaultOptions);
168168
} catch (e) {
169169
error = e;
170170
}
@@ -240,7 +240,7 @@ describe('validateAndCoerceTypes', () => {
240240

241241
let error;
242242
try {
243-
validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY)
243+
validateAndCoerceTypes(result, QUERY_RESULT_SCHEMA_KEY, undefined, defaultOptions);
244244
} catch (e) {
245245
error = e;
246246
}

src/modules/search.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import _moduleExec from '../lib/moduleExec';
88
const yf = {
99
_env,
1010
_fetch,
11+
_opts: { validation: { logErrors: true }},
1112
_moduleExec,
1213
search
1314
};
@@ -36,15 +37,19 @@ describe('search', () => {
3637
});
3738

3839
it('throws on unexpected input', async () => {
40+
yf._opts.validation.logErrors = false;
3941
await expect(yf.search('AAPL', {}, { devel: 'search-fakeBadResult.json' }))
4042
.rejects.toThrow(/Failed Yahoo Schema/)
43+
yf._opts.validation.logErrors = true;
4144
});
4245

4346
it('does not throw on unexpected input if called with {validateResult: false}', async () => {
47+
yf._opts.validation.logErrors = false;
4448
await expect(yf.search('AAPL', {}, {
4549
devel: 'search-fakeBadResult.json',
4650
validateResult: false
4751
})).resolves.toBeDefined();
52+
yf._opts.validation.logErrors = true;
4853
});
4954

5055
});

0 commit comments

Comments
 (0)