Screen%20region%202014-09-18%20at%2017.37.07_large

Avishaan Sethi

Use Multiple Values for a Single Jasmine Suite

An alternative to npm libraries like 'jasmine-where' and full blown data provider pattern.

Often, we want to reuse the test suites and encompassing assertions when writing out test cases but want to input different values. Currently, jasmine doesn't provide any kind of pattern for doing so. If you don't want to use another 3rd party library, such as 'jasmine-where', there is a relatively easy way to do so below. In . . .

Read More

October 29, 2014

Node.js Alternate Config File

An alternate config file in node for setting variables based on current env without the overhead of another library with more flexibility than a .json file.

Let me answer some questions to start with.

Why not just use a config.json file and then require that?

  1. You can't reference your NODE_ENV variable.
  2. You can't require any additional files. What if you want to use reuse a field in an existing library's config file or from your package.json!?
  3. . . .

Read More

Posted in: nodejshowto

October 19, 2014

Use 'type' as a Property Name in a Mongoose Doc

The syntax is a little different since 'type' already has a meaning in a Mongoose schema.

This will not work.

var contractSchema = new mongoose.Schema({
 questions: [{
 type: {type: 'string'},
 question: 'string'
 }],
 version: String,
 state: String
});

This will work.

var contractSchema = new mongoose.Schema({
 questions: [{
 type: 'string'
  . . .

Read More

Posted in: mongoosejsnodejs

October 19, 2014

Mongoose v3 Embedded Object without Explicit Subschema Delcaration

A quick code example of how to embed a subdocument/collection of objects in a Mongoose model without create a whole other explicit subdoc reference.

Jump in!

var contractSchema = new mongoose.Schema({
 questions: [{
 type: {type: 'string'},
 question: 'string',
 choices: ['string'],
 cycles: 'string'
 }],
 version: String,
 state: String
});

This will allow us to have a document in the following form.

var . . .

Read More

Posted in: mongoosejsnodejs

October 19, 2014

Check Code Coverage on Your Node.js App

We all talk about it, but no one does it. Part of the reason is because once you get past the basics, there is no good documentation. Here is how to do it with Istanbul and Jasmine-node/Jasmine for the integration and unit tests of your Node.js App

I am going to talk about one very specific item in this article since it barely exists anywhere on the internet. How to run both your integration tests and unit tests in such a way that you can actually see the whole code coverage.
I am not going to tell you to download another plugin, I want you to see how this will actually work.
I . . .

Read More

October 13, 2014

Comparing Mongoose Object Ids

Forget about finding a deeply nested id property that you have to call the .toString() method on in order to compare.

Forget about nonsense like this in order to compare two Mongoose Ids

if (val.user.toString() === submissionDoc.owner._id.toString()){
 //do stuff
}

Use a built in Mongoose function instead!

if (val.user.equals(submissionDoc.owner._id)){
 //do stuff
}

Or don't, be convoluted, see if anyone wants to . . .

Read More

Posted in: mongoosejsnodejs

September 24, 2014

Archive