I have this one-liner I need to test using jest
export const matchUriRE = /^([^:]*):([^:]*):(.*)$/;
How to test it? Thanks in advance.
I know the question is quite old by now and I don't even know if the following solution already existed at the time of asking, but I think the Jest-most way would be:
it('matches URI', () => {
const uriRegEx = /^([^:]*):([^:]*):(.*)$/;
const uri = 'http://google.com:4443/';
expect(uri).toMatch(uriRegEx);
});
Potentially also produces a more descriptive error message in case of failure.
For further reference: https://jestjs.io/docs/en/expect#tomatchregexporstring
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With