question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow any object to match Object

See original GitHub issue

I’ve got a task to add simple-schema to a pretty large application. One of the field in a collection was a large object fetched directly from an external package (payment system). I’ve marked it as {type: Object, optional: true, blackbox: true}. Then I got an error:

Error: failed validation: someDumbField: must be an object

I’ve checked and the value passed to someDumbField was an object indeed. Then it took me quite a bit digging to figure out that simple-schema also checks the prototype of the object.

I’m not convinced this is the right solution – what is the reason behind checking the prototype? Our object was perfectly serializable and just pushing it to db worked well.

If checking the prototype is the way to go, the error message should reflect that to avoid confusion like mine. Something like someDumbField: must be a plain object.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
abeckscommented, Apr 6, 2016

@aldeed this is killing me when trying to use stampit. Using composition, I dont have a hard type I can validate against.

I have stamps that look like:

const someType = stampit().methods({ .... });
let something = someType();
// comes out as an Object, but the prototype is not directly Object's prototype.

and validators for my templates that look like:

Template.something.onCreated(function(){
   new SimpleSchema({
      something: {
         type: Object
      }
   }).validate(this.data);
});

As per the Meteor Guide: http://guide.meteor.com/blaze.html#validate-data-context

Validation fails if type is set to Object, or a SimpleSchema, and regardless of the blackbox setting. Right now it looks like I literally cannot validate a composed object.

0reactions
aldeedcommented, Dec 26, 2016

Sorry, changelog is on v2 branch (https://github.com/aldeed/meteor-simple-schema/blob/v2/CHANGELOG.md#200), but I recommend using the npm package directly. Also, for collection2, see https://github.com/aldeed/meteor-collection2#important-note-the-version-in-this-repo-is-deprecated

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Array/Object partial match with objectContaining and ...
It's possible to do partial matches on Arrays and Objects in Jest using expect.objectContaining and expect.arrayContaining .
Read more >
Jest allow multi types for object structure match - Stack Overflow
I am trying to create a test with jest which has to check if an object key is a ...
Read more >
Jest partial matching on objects, arrays and functions
Partial matching objects in an array​​ With an array of objects, we can use a combination of Jest's arrayContaining and objectContaining . This ......
Read more >
Expect - Jest
Matchers should return an object (or a Promise of an object) with two keys. pass indicates whether there was a match or not,...
Read more >
Python RegEx Match Object - W3Schools
A Match Object is an object containing information about the search and the result. Example. Do a search that will return a Match...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found