Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
testing mongoose validation with vows
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alberto Gori  
View profile  
 More options Nov 3 2012, 12:39 pm
From: Alberto Gori <forzaton...@gmail.com>
Date: Sat, 3 Nov 2012 09:39:31 -0700 (PDT)
Local: Sat, Nov 3 2012 12:39 pm
Subject: testing mongoose validation with vows

I am trying to test validation on a very simple mongoose model, but I have
some problem with exceptions.

//model.js

var ResourceDef = new Schema({
name: {type: String, required: true},
content: String,

});

var Resource = mongoose.model('Resources', ResourceDef);

//test.js

vows.describe('test model behavior').addBatch({
 'validating a Resource object with name equals to null': {
 topic: function() {
 new model.Resource({
name: null,
content: '.....',

}).validate(this.callback);
},

 'should throw an error': function(e) {
assert.ok(e);

}
 }
}).export(module);

I get this error:

    validating a Resource object with name equals to null
      ✗ should throw an error
        » An unexpected error was caught: ValidationError: Validator
"required" failed for path name

I don't understand why mongoose is throwing that ValidationError!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
George Snelling  
View profile  
 More options Nov 4 2012, 1:48 am
From: George Snelling <georg...@gmail.com>
Date: Sat, 3 Nov 2012 22:48:38 -0700 (PDT)
Local: Sun, Nov 4 2012 1:48 am
Subject: Re: testing mongoose validation with vows

Try posting your question here:
 https://groups.google.com/forum/?fromgroups=#!forum/mongoose-orm

-g


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto Gori  
View profile  
 More options Nov 4 2012, 6:07 am
From: Alberto Gori <forzaton...@gmail.com>
Date: Sun, 4 Nov 2012 03:07:59 -0800 (PST)
Local: Sun, Nov 4 2012 6:07 am
Subject: Re: testing mongoose validation with vows

I discovered that the problem is not inherent to mongoose validation
method, but to vows. Incredibly vows fails to manage Error in callback. For
example:

'this model': {
    topic: function() {this.callback(new Error('error!!!'))}
    'should throw an error': function(e) {asser.ok(e);}

}

this very simple test fails with

 » An unexpected error was caught: Error: error!

I thought vows was a solid test library...what happened?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
papandreou  
View profile  
 More options Nov 5 2012, 3:14 am
From: papandreou <andreaslindpeter...@gmail.com>
Date: Mon, 5 Nov 2012 00:14:43 -0800 (PST)
Local: Mon, Nov 5 2012 3:14 am
Subject: Re: testing mongoose validation with vows

It's actually a conscious design choice in vows, but I agree that it's a
mistake. In the async case (last time I checked) it looks at the arity of
your vow function (function.length), and if it takes less than two
arguments, it assumes that you don't want the error passed to your
function, just the "result", and that you want to classify it as an error
every time an error is passed to this.callback.

I guess the underlying assumption is that an async function will always
deliver a result to its callback, but it's clearly too magic. It has caused
a lot of wtfs for me and my team. The "fix" is to add a bogus 2nd argument
to your vow function.

Best regards,
Andreas Lind Petersen (papandreou)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chad Engler  
View profile  
 More options Nov 5 2012, 9:03 am
From: "Chad Engler" <Chad.Eng...@patlive.com>
Date: Mon, 5 Nov 2012 09:03:17 -0500
Local: Mon, Nov 5 2012 9:03 am
Subject: RE: [nodejs] Re: testing mongoose validation with vows

I was just having this exact issue the other day, thanks for the catch
Papandreou! You just saved me some serious time.

-Chad

From: nodejs@googlegroups.com [mailto:nodejs@googlegroups.com] On Behalf
Of papandreou
Sent: Monday, November 05, 2012 3:15 AM
To: nodejs@googlegroups.com
Subject: [nodejs] Re: testing mongoose validation with vows

It's actually a conscious design choice in vows, but I agree that it's a
mistake. In the async case (last time I checked) it looks at the arity
of your vow function (function.length), and if it takes less than two
arguments, it assumes that you don't want the error passed to your
function, just the "result", and that you want to classify it as an
error every time an error is passed to this.callback.

I guess the underlying assumption is that an async function will always
deliver a result to its callback, but it's clearly too magic. It has
caused a lot of wtfs for me and my team. The "fix" is to add a bogus 2nd
argument to your vow function.

Best regards,

Andreas Lind Petersen (papandreou)

On Sunday, November 4, 2012 12:07:59 PM UTC+1, Alberto Gori wrote:

I discovered that the problem is not inherent to mongoose validation
method, but to vows. Incredibly vows fails to manage Error in callback.
For example:

'this model': {

    topic: function() {this.callback(new Error('error!!!'))}

    'should throw an error': function(e) {asser.ok(e);}

}

this very simple test fails with

 > An unexpected error was caught: Error: error!

I thought vows was a solid test library...what happened?

--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto Gori  
View profile  
 More options Nov 7 2012, 3:11 pm
From: Alberto Gori <forzaton...@gmail.com>
Date: Wed, 7 Nov 2012 12:11:49 -0800 (PST)
Local: Wed, Nov 7 2012 3:11 pm
Subject: Re: testing mongoose validation with vows

I discovered that Vows has a not documented feature that completely solves
this problem:

vows.describe('...

}).export(module, { error: false });

{error: false} is the answer!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto Gori  
View profile  
 More options Nov 7 2012, 3:12 pm
From: Alberto Gori <forzaton...@gmail.com>
Date: Wed, 7 Nov 2012 12:12:18 -0800 (PST)
Local: Wed, Nov 7 2012 3:12 pm
Subject: Re: testing mongoose validation with vows

Il giorno mercoledì 7 novembre 2012 21:11:49 UTC+1, Alberto Gori ha scritto:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »