samedi 27 juin 2015

Mocha Chai regex are equals

I am trying to test the behaviour of a method that produce regex.

Using Mocha/Chai test suite I have the following code :

describe('regexTest',function () {
  it('should return a regexp', function () {
    var regex = regexTest();
    assert.equal(regex, /someregex/);
  });
});

But it seems that the code above doesn't work. I tried in the chrome console :

/a/ == /a/ 
> false

For the moment the only way I found is to compare the toString of the two regex (that should be equals and that I can compare) :

describe('regexTest',function () {
  it('should return a regexp', function () {
    var regex = regexTest();
    assert.equal(regex.toString(), '/someregex/');
  });
});

Do you know a better way to do this ? Because I find this not really clean ...

Aucun commentaire:

Enregistrer un commentaire