forked from vscode-icons/vscode-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for error handling (vscode-icons#1670)
- Loading branch information
1 parent
2776571
commit 61b705f
Showing
9 changed files
with
928 additions
and
838 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// tslint:disable only-arrow-functions | ||
// tslint:disable no-unused-expression | ||
import { expect } from 'chai'; | ||
import * as sinon from 'sinon'; | ||
import { ErrorHandler } from '../src/errorHandler'; | ||
|
||
describe('ErrorHandler: tests', function() { | ||
context('ensures that', function() { | ||
let sandbox: sinon.SinonSandbox; | ||
let consoleErrorStub: sinon.SinonStub; | ||
|
||
beforeEach(function() { | ||
sandbox = sinon.createSandbox(); | ||
consoleErrorStub = sandbox.stub(console, 'error'); | ||
}); | ||
|
||
afterEach(function() { | ||
sandbox.restore(); | ||
}); | ||
|
||
context('it logs', function() { | ||
it('the error stack', function() { | ||
const error = new Error(); | ||
error.stack = 'contextOfStack'; | ||
ErrorHandler.logError(error); | ||
expect(consoleErrorStub.called).to.be.true; | ||
expect(consoleErrorStub.calledWithMatch(/contextOfStack/)).to.be.true; | ||
expect(error) | ||
.to.haveOwnProperty('stack') | ||
.and.to.equal(error.stack); | ||
}); | ||
|
||
it('the error message, when no error stack is available', function() { | ||
const error = new Error('message'); | ||
delete error.stack; | ||
ErrorHandler.logError(error); | ||
expect(consoleErrorStub.called).to.be.true; | ||
expect(consoleErrorStub.calledWithMatch(/message/)).to.be.true; | ||
expect(error).to.not.haveOwnProperty('stack').to.be.true; | ||
}); | ||
|
||
it('the error iteslef, when no error stack and message are available', function() { | ||
const error = new Error(); | ||
delete error.stack; | ||
delete error.message; | ||
ErrorHandler.logError(error); | ||
expect(consoleErrorStub.called).to.be.true; | ||
expect(error).to.not.haveOwnProperty('stack').to.be.true; | ||
expect(error).to.not.haveOwnProperty('message').to.be.true; | ||
}); | ||
|
||
it('handled errors', function() { | ||
const error = new Error(); | ||
ErrorHandler.logError(error, true); | ||
expect(consoleErrorStub.called).to.be.true; | ||
expect(consoleErrorStub.calledWithMatch(/Handled/)).to.be.true; | ||
}); | ||
|
||
it('unhandled errors', function() { | ||
const error = new Error(); | ||
delete error.stack; | ||
delete error.message; | ||
ErrorHandler.logError(error); | ||
expect(consoleErrorStub.called).to.be.true; | ||
expect(consoleErrorStub.calledWithMatch(/Unhandled/)).to.be.true; | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters