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

BaseService tests: Use Chai #1450

Merged
merged 4 commits into from
Jan 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions services/base.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';

const assert = require('assert');
const { expect } = require('chai');
const sinon = require('sinon');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding require('../lib/register-chai-plugins.spec'); here allows to run tests only from this file (using command line or IDE). Otherwise we will get Error: Invalid Chai property: calledOnce ...

const BaseService = require('./base');

require('../lib/register-chai-plugins.spec');

class DummyService extends BaseService {
async handle({someArg}) {
return {
Expand Down Expand Up @@ -37,12 +39,12 @@ describe('BaseService', () => {
});

it('registers the service', () => {
assert(mockCamp.route.calledOnce);
assert.equal(mockCamp.route.getCall(0).args[0].toString(), expectedRouteRegex);
expect(mockCamp.route).to.have.been.calledOnce;
expect(mockCamp.route).to.have.been.calledWith(expectedRouteRegex);
});

it('handles the request', async () => {
assert(mockHandleRequest.calledOnce);
expect(mockHandleRequest).to.have.been.calledOnce;
const requestHandler = mockHandleRequest.getCall(0).args[0];

const mockSendBadge = sinon.spy();
Expand All @@ -56,8 +58,8 @@ describe('BaseService', () => {
mockRequest
);

assert(mockSendBadge.calledOnce);
assert(mockSendBadge.calledWith(
expect(mockSendBadge).to.have.been.calledOnce;
expect(mockSendBadge).to.have.been.calledWith(
/*format*/ 'svg',
{
message: 'Hello bar',
Expand All @@ -70,7 +72,7 @@ describe('BaseService', () => {
colorA: undefined,
colorB: undefined,
}
));
);
});
});
});