MCPcopy
hub / github.com/sequelize/sequelize / expectPerDialect

Function expectPerDialect

test/support.js:318–377  ·  view source on GitHub ↗
(method, assertions)

Source from the content-addressed store, hash-verified

316}
317
318function expectPerDialect(method, assertions) {
319 const expectations = Object.create(null);
320
321 for (const [key, value] of Object.entries(assertions)) {
322 const acceptedDialects = key.split(' ');
323
324 for (const dialect of acceptedDialects) {
325 if (dialect === 'default' && acceptedDialects.length > 1) {
326 throw new Error(
327 'The \'default\' expectation cannot be combined with other dialects.'
328 );
329 }
330
331 if (expectations[dialect] !== undefined) {
332 throw new Error(`The expectation for ${dialect} was already defined.`);
333 }
334
335 expectations[dialect] = value;
336 }
337 }
338
339 let result;
340
341 try {
342 result = method();
343 } catch (error) {
344 assert(error instanceof Error, 'method threw a non-error');
345
346 result = error;
347 }
348
349 let expectation = expectations[Support.sequelize.dialect.name];
350 expectation = expectation != null ? expectation : expectations.default;
351
352 if (expectation === undefined) {
353 throw new Error(
354 `No expectation was defined for ${Support.sequelize.dialect.name} and the 'default' expectation has not been defined.`
355 );
356 }
357
358 if (expectation instanceof Error) {
359 assert(
360 result instanceof Error,
361 `Expected method to error with "${
362 expectation.message
363 }", but it returned ${inspect(result)}.`
364 );
365
366 expect(result.message).to.equal(expectation.message);
367 } else {
368 assert(
369 !(result instanceof Error),
370 `Did not expect query to error, but it errored with ${
371 result instanceof Error ? result.message : ''
372 }`
373 );
374
375 assertMatchesExpectation(result, expectation);

Callers 1

sql.test.jsFile · 0.85

Calls 2

assertMatchesExpectationFunction · 0.85
createMethod · 0.45

Tested by

no test coverage detected