molnarg / js-schema

Simple and intuitive schema validator
http://molnarg.github.com/js-schema/
MIT License
387 stars 45 forks source link

sometimes getting `constructor.schema.unwrap is not a function` errors #51

Closed pkyeck closed 7 years ago

pkyeck commented 7 years ago

I don't really know why this is happening, but I started getting

TypeError: constructor.schema.unwrap is not a function
    at Array.<anonymous> (/opt/node_modules/js-schema/lib/patterns/class.js:36:31)
    at lastDefinedResult (/opt/node_modules/js-schema/lib/BaseSchema.js:107:26)
    at Array.<anonymous> (/opt/node_modules/js-schema/lib/patterns/object.js:216:27)
    at lastDefinedResult (/opt/node_modules/js-schema/lib/BaseSchema.js:107:26)
    at Array.<anonymous> (/opt/node_modules/js-schema/lib/patterns/object.js:216:27)
    at lastDefinedResult (/opt/node_modules/js-schema/lib/BaseSchema.js:107:26)
    at Object.resolve (/opt/node_modules/js-schema/lib/extensions/Schema.js:10:31)
    at Object.ref.resolve (/opt/node_modules/js-schema/lib/extensions/Schema.js:33:46)
    at module.exports (/opt/node_modules/js-schema/lib/schema.js:22:17)
    ...

when trying to do this in a module:

exports.postSubmit = co(function*(req, res, next) {
  try {
    let validate = schema({
      nr: /[0-9]{7}|abc\-[a-z\-]+/i,
      index: Number,
      lNr: Number,
      value: [Number, String, Boolean],
      '*': null
    });
  } catch (err) {}
});

When moving the code outside of the coroutine, I don't get this error ..!? This worked before - even inside a coroutine - but doesn't right now.

pkyeck commented 7 years ago

I think it had something to do with using proxyquire in my test-setup and mocking something I shouldn't have. Completely rewriting the test got rid of the error message.