vendredi 1 juillet 2016

Should I test if a module has some properties?

I've been writing test (in JavaScript) for the last two months. And, I have the habit of checking if module has some properties.

For example:

// test/foo.js
const Foo = require('../lib/foo');
const Expect = require('chai').expect;

describe('Foo API', () => {
    it('should have #do and #dont properties', () => {
        Expect(foo).to.have.property('do')
            .and.to.be.a('function');

        Expect(foo).to.have.property('dont')
            .and.to.be.a('function');
        });
     });
});

And, I've been wondering if I am doing the right things. Just wanna know a few things:

  1. Is this pattern "right"?

    • Is it widely used?
    • Are there other ways to do it?
  2. If its not "right"?

    • Why?
  3. Does it even makes sense?

    • I mean, it is unnecesary or redundant?

Aucun commentaire:

Enregistrer un commentaire