0

I've got a simple mixin:

var _ = require('lodash')
_.mixin(require('lodash-uuid'))

Which I can use in code like so:

if (_.isUuid(someValue)) {
   // it's a uuid!
}

I'd like to be able to extend -based tests to leverage this module, for example:

response.should.have.property('uuid').which.is.a.uuid()

The docs for extending Should are a little light; I tried:

var uuid = should.extend('uuid', _.isUuid)

But that throws:

TypeError: response.should.have.property(...).which.is.a.uuid is not a function

1 Answer 1

2

You used not right method. Method you used is to add should getter to any object. You need to use should.Assertion.add, like:

var should = require('should');

should.Assertion.add('uuid', function() {
  this.params = { operator: 'to be UUID' };

  this.assert(_.isUuid(this.obj));
});
2
  • Nice! Thanks. Should.js docs didn't leave any indication that this would be the way to do it... Jan 8, 2016 at 19:19
  • Yep, probably. I will try to fix this later. Jan 8, 2016 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.