本文整理匯總了TypeScript中jest-snapshot-serializer-raw.wrap函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript wrap函數的具體用法?TypeScript wrap怎麽用?TypeScript wrap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了wrap函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('traverses directory tree up until it finds jest.config', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
const slash = require('slash');
test('banana', () => expect(1).toBe(1));
test('abc', () => console.log(slash(process.cwd())));
`,
'jest.config.js': `module.exports = {testRegex: '.*-banana.js'};`,
'package.json': '{}',
'some/nested/directory/file.js': '// nothing special',
});
const {stderr, status, stdout} = runJest(
path.join(DIR, 'some', 'nested', 'directory'),
['-w=1', '--ci=false'],
{skipPkgJsonCheck: true},
);
// Snapshot the console.loged `process.cwd()` and make sure it stays the same
expect(
wrap(stdout.replace(/^\W+(.*)e2e/gm, '<<REPLACED>>')),
).toMatchSnapshot();
const {rest, summary} = extractSummary(stderr);
expect(status).toBe(0);
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
});
示例2: it
it('works with escaped regex', () => {
// Write the first snapshot
let result = runJest('snapshot-escape', [
'-w=1',
'--ci=false',
'snapshotEscapeRegex.js',
]);
let stderr = result.stderr;
expect(stderr).toMatch('2 snapshots written from 1 test suite.');
expect(result.status).toBe(0);
expect(wrap(extractSummary(stderr).summary)).toMatchSnapshot();
result = runJest('snapshot-escape', [
'-w=1',
'--ci=false',
'snapshotEscapeRegex.js',
]);
stderr = result.stderr;
// Make sure we aren't writing a snapshot this time which would
// indicate that the snapshot couldn't be loaded properly.
expect(stderr).not.toMatch('Snapshot Summary');
expect(wrap(extractSummary(stderr).summary)).toMatchSnapshot();
expect(result.status).toBe(0);
});
示例3: test
test('skips with expand arg', () => {
const filename = 'skipsConstructs.test.js';
const content = `
it('it', () => {});
xtest('xtest', () => {});
xit('xit', () => {});
it.skip('it.skip', () => {});
test.skip('test.skip', () => {});
xdescribe('xdescribe', () => {
it('it', () => {});
test('test', () => {});
});
describe.skip('describe.skip', () => {
test('test', () => {});
describe('describe', () => {
test('test', () => {});
});
});
`;
writeFiles(TEST_DIR, {[filename]: content});
const {stderr, status} = runJest(DIR, ['--expand']);
expect(status).toBe(0);
const {summary, rest} = extractSummary(stderr);
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
});
示例4: test
test('do not indent empty lines', () => {
const filename = 'empty-line-indent.test.js';
const template = makeTemplate(
`test('inline snapshots', () => expect($1).toMatchInlineSnapshot());\n`,
);
{
writeFiles(TESTS_DIR, {
[filename]: template(['`hello\n\nworld`']),
});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
const fileAfter = readFile(filename);
expect(stderr).toMatch('1 snapshot written from 1 test suite.');
expect(status).toBe(0);
expect(wrap(fileAfter)).toMatchSnapshot('initial write');
}
{
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
const fileAfter = readFile(filename);
expect(stderr).toMatch('Snapshots: 1 passed, 1 total');
expect(stderr).not.toMatch('1 snapshot written from 1 test suite.');
expect(status).toBe(0);
expect(wrap(fileAfter)).toMatchSnapshot('snapshot passed');
}
});
示例5: test
test('console printing', () => {
const {stderr, status} = runJest('console');
const {summary, rest} = extractSummary(stderr);
expect(status).toBe(0);
expect(wrap(rest)).toMatchSnapshot();
expect(wrap(summary)).toMatchSnapshot();
});
示例6: test
test('handles property matchers', () => {
const filename = 'handle-property-matchers.test.js';
const template = makeTemplate(`test('handles property matchers', () => {
expect({createdAt: $1}).toMatchInlineSnapshot({createdAt: expect.any(Date)});
});
`);
{
writeFiles(TESTS_DIR, {[filename]: template(['new Date()'])});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
const fileAfter = readFile(filename);
expect(stderr).toMatch('1 snapshot written from 1 test suite.');
expect(status).toBe(0);
expect(wrap(fileAfter)).toMatchSnapshot('initial write');
}
{
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
const fileAfter = readFile(filename);
expect(stderr).toMatch('Snapshots: 1 passed, 1 total');
expect(status).toBe(0);
expect(wrap(fileAfter)).toMatchSnapshot('snapshot passed');
}
{
writeFiles(TESTS_DIR, {
[filename]: readFile(filename).replace('new Date()', '"string"'),
});
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
const fileAfter = readFile(filename);
expect(stderr).toMatch(
'Received value does not match snapshot properties for "handles property matchers 1".',
);
expect(stderr).toMatch('Snapshots: 1 failed, 1 total');
expect(status).toBe(1);
expect(wrap(fileAfter)).toMatchSnapshot('snapshot failed');
}
{
writeFiles(TESTS_DIR, {
[filename]: readFile(filename).replace('any(Date)', 'any(String)'),
});
const {stderr, status} = runJest(DIR, [
'-w=1',
'--ci=false',
filename,
'-u',
]);
const fileAfter = readFile(filename);
expect(stderr).toMatch('1 snapshot updated from 1 test suite.');
expect(status).toBe(0);
expect(wrap(fileAfter)).toMatchSnapshot('snapshot updated');
}
});