The Wayback Machine - https://web.archive.org/web/20200611030353/https://github.com/goldbergyoni/javascript-testing-best-practices/issues/25
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Mocha's context (alias for describe) #25

Open
kbariotis opened this issue Aug 17, 2019 · 3 comments
Open

Use Mocha's context (alias for describe) #25

kbariotis opened this issue Aug 17, 2019 · 3 comments

Comments

@kbariotis
Copy link

@kbariotis kbariotis commented Aug 17, 2019

I like Mocha's context alias for describe. Consider the following example (from 1.1):

//1. unit under test
describe('Products Service', function() {
  describe('Add new product', function() {
    //2. scenario and 3. expectation
    it('When no price is specified, then the product status is pending approval', ()=> {
      const newProduct = new ProductService().add(...);
      expect(newProduct.status).to.equal('pendingApproval');
    });
  });
});

It could be rewritten:

//1. unit under test
describe('Products Service', () => {
  // 2. specific capability
  describe('Add new product',() => {
    // 3. scenario
    context('When no price is specified', () => {
      // 4. expectation
      it('Should have product status as pending approval', () => {
        const newProduct = new ProductService().add(...);
        expect(newProduct.status).to.equal('pendingApproval');
      });
    });
  });
});
@goldbergyoni
Copy link
Owner

@goldbergyoni goldbergyoni commented Aug 19, 2019

Great tip! Wasn't aware of that 😮

Can you share a link to its documentation?

@kbariotis
Copy link
Author

@kbariotis kbariotis commented Aug 20, 2019

@goldbergyoni
Copy link
Owner

@goldbergyoni goldbergyoni commented Aug 24, 2019

I like how it structures the test.

Have a look at RITE, it's also a nice way to push toward more structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.