-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
|
||
const BaseService = require('./base'); | ||
|
@@ -37,12 +37,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.getCall(0).args[0].toString()).to.equal(expectedRouteRegex.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we replace it with expect(mockCamp.route).to.have.been.calledWith(expectedRouteRegex); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately it fails, because we need the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, no, you're right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ Chai |
||
}); | ||
|
||
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(); | ||
|
@@ -56,8 +56,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', | ||
|
@@ -70,7 +70,7 @@ describe('BaseService', () => { | |
colorA: undefined, | ||
colorB: undefined, | ||
} | ||
)); | ||
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
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 getError: Invalid Chai property: calledOnce ...