mercredi 1 janvier 2020

How to use sinon.match with regex

Simple enough question - I'm testing JavaScript, and trying to assert that a datetime is correctly formatted.

Here're the variables:

let regexp = /^["']?d{4}-d[0-2]-[0-3]dT[0-2]d:[0-6]d:[0-6]d["']?/;
let dateToAssert = "2019-12-11T16:48:59";

Now I need to use something like sinon.match(regexp, dateToAssert);.

But:

sinon.assert.match(regexp, dateToAssert); returns AssertError: expected value to match

sinon.match(regexp, dateToAssert); returns Error: Timeout of 2000ms exceeded.

How do I tell the function to compare as regex and not as string? The first place I looked was the sinon documentation, but all I can find is

sinon.match(regexp);
Requires the value to be a string and match the given regular expression.

Why is there only one parameter? How is the program supposed to know what it's comparing the regex against?

Anyone prepared to help me out with the correct syntax here?

Aucun commentaire:

Enregistrer un commentaire