本文整理匯總了TypeScript中pretty-format.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('serializes/deserializes in disk', () => {
serializer.writeFileSync(file, obj);
expect(prettyFormat(serializer.readFileSync(file))).toEqual(
prettyFormat(obj),
);
});
示例2: test
test('calls global test title with %p placeholder injected at the correct positions', () => {
const globalTestMocks = getGlobalTestMocks();
const eachObject = each.withGlobal(globalTestMocks)([
['string1', 'pretty1', 'string2', 'pretty2'],
['string1', 'pretty1', 'string2', 'pretty2'],
]);
const testFunction = get(eachObject, keyPath);
testFunction('expected string: %s %p %s %p', noop);
const globalMock = get(globalTestMocks, keyPath);
expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
`expected string: string1 ${pretty('pretty1')} string2 ${pretty(
'pretty2',
)}`,
expectFunction,
undefined,
);
expect(globalMock).toHaveBeenCalledWith(
`expected string: string1 ${pretty('pretty1')} string2 ${pretty(
'pretty2',
)}`,
expectFunction,
undefined,
);
});
示例3: comparePrimitive
function comparePrimitive(
a: number | boolean,
b: number | boolean,
options?: JestDiffOptions,
) {
return diffStrings(
prettyFormat(a, FORMAT_OPTIONS),
prettyFormat(b, FORMAT_OPTIONS),
options,
);
}
示例4: TypeError
constructor(value: unknown) {
if (isPrimitive(value)) {
throw new TypeError(
[
'Primitives cannot leak memory.',
'You passed a ' + typeof value + ': <' + prettyFormat(value) + '>',
].join(' '),
);
}
let weak;
try {
// eslint-disable-next-line import/no-extraneous-dependencies
weak = require('weak');
} catch (err) {
if (!err || err.code !== 'MODULE_NOT_FOUND') {
throw err;
}
throw new Error(
'The leaking detection mechanism requires the "weak" package to be installed and work. ' +
'Please install it as a dependency on your main project',
);
}
weak(value, () => (this._isReferenceBeingHeld = false));
this._isReferenceBeingHeld = true;
// Ensure value is not leaked by the closure created by the "weak" callback.
value = null;
}
示例5: Error
export const validateArrayTable = (table: any) => {
if (!Array.isArray(table)) {
throw new Error(
'`.each` must be called with an Array or Tagged Template Literal.\n\n' +
`Instead was called with: ${pretty(table, {
maxDepth: 1,
min: true,
})}\n`,
);
}
if (isTaggedTemplateLiteral(table)) {
if (isEmptyString(table[0])) {
throw new Error(
'Error: `.each` called with an empty Tagged Template Literal of table data.\n',
);
}
throw new Error(
'Error: `.each` called with a Tagged Template Literal with no data, remember to interpolate with ${expression} syntax.\n',
);
}
if (isEmptyTable(table)) {
throw new Error(
'Error: `.each` called with an empty Array of table data.\n',
);
}
};
示例6: fn
test('min option', () => {
const fn = jest.fn(val => val);
fn({key: 'value'});
const expected =
'[MockFunction] {"calls": [[{"key": "value"}]], "results": [{"type": "return", "value": {"key": "value"}}]}';
expect(prettyFormat(fn, {min: true, plugins: [plugin]})).toBe(expected);
});
示例7: Error
const _formatError = (
errors?: Circus.Exception | [Circus.Exception | undefined, Circus.Exception],
): string => {
let error;
let asyncError;
if (Array.isArray(errors)) {
error = errors[0];
asyncError = errors[1];
} else {
error = errors;
asyncError = new Error();
}
if (error) {
if (error.stack) {
return error.stack;
}
if (error.message) {
return error.message;
}
}
asyncError.message = `thrown: ${prettyFormat(error, {maxDepth: 3})}`;
return asyncError.stack;
};
示例8: addExtraLineBreaks
export const serialize = (data: string): string =>
addExtraLineBreaks(
normalizeNewlines(
prettyFormat(data, {
escapeRegex: true,
plugins: getSerializers(),
printFunctionName: false,
}),
),
);
示例9: expect
test('maxDepth option', () => {
const fn1 = jest.fn();
fn1.mockName('atDepth1');
fn1('primitive', {key: 'value'});
const fn2 = jest.fn();
fn2.mockName('atDepth2');
fn2('primitive', {key: 'value'});
const fn3 = jest.fn();
fn3.mockName('atDepth3');
fn3('primitive', {key: 'value'});
const val = {
fn1,
greaterThan1: {
fn2,
greaterThan2: {
fn3,
},
},
};
const expected = [
'Object {', // ++depth === 1
' "fn1": [MockFunction atDepth1] {',
' "calls": Array [', // ++depth === 2
' Array [', // ++depth === 3
' "primitive",',
' [Object],', // ++depth === 4
' ],',
' ],',
' "results": Array [', // ++depth === 2
' Object {', // ++depth === 3
' "type": "return",',
' "value": undefined,',
' },',
' ],',
' },',
' "greaterThan1": Object {', // ++depth === 2
' "fn2": [MockFunction atDepth2] {',
' "calls": Array [', // ++depth === 3
' [Array],', // ++depth === 4
' ],',
' "results": Array [', // ++depth === 3
' [Object],', // ++depth === 4
' ],',
' },',
' "greaterThan2": Object {', // ++depth === 3
' "fn3": [MockFunction atDepth3] {',
' "calls": [Array],', // ++depth === 4
' "results": [Array],', // ++depth === 4
' },',
' },',
' },',
'}',
].join('\n');
expect(prettyFormat(val, {maxDepth: 3, plugins: [plugin]})).toBe(expected);
});