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
den bardadym
  • 2,747
  • 3
  • 25
  • 27
brandonscript
  • 68,675
  • 32
  • 163
  • 220

1 Answers1

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));
});
den bardadym
  • 2,747
  • 3
  • 25
  • 27