本文整理匯總了TypeScript中jest-matcher-utils.matcherErrorMessage函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript matcherErrorMessage函數的具體用法?TypeScript matcherErrorMessage怎麽用?TypeScript matcherErrorMessage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了matcherErrorMessage函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Error
const ensureMock = (mockOrSpy: any, matcherName: any) => {
if (
!mockOrSpy ||
((mockOrSpy.calls === undefined || mockOrSpy.calls.all === undefined) &&
mockOrSpy._isMockFunction !== true)
) {
throw new Error(
matcherErrorMessage(
matcherHint('[.not]' + matcherName, 'jest.fn()', ''),
`${RECEIVED_COLOR('received')} value must be a mock or spy function`,
printWithType('Received', mockOrSpy, printReceived),
),
);
}
};
示例2: function
function(this: MatcherState, received: Function, expected: any) {
const options = {
isNot: this.isNot,
promise: this.promise,
};
let thrown = null;
if (fromPromise && isError(received)) {
thrown = getThrown(received);
} else {
if (typeof received !== 'function') {
if (!fromPromise) {
const placeholder = expected === undefined ? '' : 'expected';
throw new Error(
matcherErrorMessage(
matcherHint(matcherName, undefined, placeholder, options),
`${RECEIVED_COLOR('received')} value must be a function`,
printWithType('Received', received, printReceived),
),
);
}
} else {
try {
received();
} catch (e) {
thrown = getThrown(e);
}
}
}
if (expected === undefined) {
return toThrow(matcherName, options, thrown);
} else if (typeof expected === 'function') {
return toThrowExpectedClass(matcherName, options, thrown, expected);
} else if (typeof expected === 'string') {
return toThrowExpectedString(matcherName, options, thrown, expected);
} else if (expected !== null && typeof expected.test === 'function') {
return toThrowExpectedRegExp(matcherName, options, thrown, expected);
} else if (
expected !== null &&
typeof expected.asymmetricMatch === 'function'
) {
return toThrowExpectedAsymmetric(matcherName, options, thrown, expected);
} else if (expected !== null && typeof expected === 'object') {
return toThrowExpectedObject(matcherName, options, thrown, expected);
} else {
throw new Error(
matcherErrorMessage(
matcherHint(matcherName, undefined, undefined, options),
`${EXPECTED_COLOR(
'expected',
)} value must be a string or regular expression or class or error`,
printWithType('Expected', expected, printExpected),
),
);
}
};
示例3: JestAssertionError
): PromiseMatcherFn => (...args) => {
const options = {
isNot,
promise: 'rejects',
};
if (!isPromise(actual)) {
throw new JestAssertionError(
matcherUtils.matcherErrorMessage(
matcherUtils.matcherHint(matcherName, undefined, '', options),
`${matcherUtils.RECEIVED_COLOR('received')} value must be a promise`,
matcherUtils.printWithType(
'Received',
actual,
matcherUtils.printReceived,
),
),
);
}
const innerErr = new JestAssertionError();
return actual.then(
result => {
outerErr.message =
matcherUtils.matcherHint(matcherName, undefined, '', options) +
'\n\n' +
`Received promise resolved instead of rejected\n` +
`Resolved to value: ${matcherUtils.printReceived(result)}`;
return Promise.reject(outerErr);
},
reason =>
makeThrowingMatcher(matcher, isNot, 'rejects', reason, innerErr).apply(
null,
args,
),
);
};
示例4: toBeInstanceOf
return {message, pass};
},
toBeInstanceOf(this: MatcherState, received: any, expected: Function) {
const matcherName = 'toBeInstanceOf';
const options: MatcherHintOptions = {
isNot: this.isNot,
promise: this.promise,
};
if (typeof expected !== 'function') {
throw new Error(
matcherErrorMessage(
matcherHint(matcherName, undefined, undefined, options),
`${EXPECTED_COLOR('expected')} value must be a function`,
printWithType('Expected', expected, printExpected),
),
);
}
const pass = received instanceof expected;
const message = pass
? () =>
matcherHint(matcherName, undefined, undefined, options) +
'\n\n' +
printExpectedConstructorNameNot('Expected constructor', expected) +
(typeof received.constructor === 'function' &&
received.constructor !== expected
? printReceivedConstructorNameNot(
示例5: toBeInstanceOf
'\n\n' +
`Expected:${isNot ? ' not' : ''} >= ${printExpected(expected)}\n` +
`Received:${isNot ? ' ' : ''} ${printReceived(received)}`;
return {message, pass};
},
toBeInstanceOf(this: MatcherState, received: any, constructor: Function) {
const constType = getType(constructor);
if (constType !== 'function') {
throw new Error(
matcherErrorMessage(
matcherHint('.toBeInstanceOf', undefined, undefined, {
isNot: this.isNot,
}),
`${EXPECTED_COLOR('expected')} value must be a function`,
printWithType('Expected', constructor, printExpected),
),
);
}
const pass = received instanceof constructor;
const message = pass
? () =>
matcherHint('.toBeInstanceOf', 'value', 'constructor', {
isNot: this.isNot,
}) +
'\n\n' +
`Expected constructor: ${EXPECTED_COLOR(
constructor.name || String(constructor),