renovate/lib/util/regex.spec.ts
2020-05-01 18:03:48 +02:00

26 lines
648 B
TypeScript

// eslint-disable-next-line import/no-extraneous-dependencies
import RE2 from 're2';
import { CONFIG_VALIDATION } from '../constants/error-messages';
import { regEx } from './regex';
describe('util/regex', () => {
beforeEach(() => {
jest.resetModules();
});
it('uses RE2', () => {
expect(regEx('foo')).toBeInstanceOf(RE2);
});
it('throws unsafe 2', () => {
expect(() => regEx(`x++`)).toThrow(CONFIG_VALIDATION);
});
it('Falls back to RegExp', () => {
jest.doMock('re2', () => {
throw new Error();
});
const regex = require('./regex');
expect(regex.regEx('foo')).toBeInstanceOf(RegExp);
});
});