mirror of
https://github.com/nasa/openmct.git
synced 2025-05-28 21:24:20 +00:00
[Actions] Test error handling
This commit is contained in:
parent
07179f7290
commit
066fd55590
@ -30,7 +30,8 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The action provider", function () {
|
describe("The action provider", function () {
|
||||||
var actions,
|
var mockLog,
|
||||||
|
actions,
|
||||||
actionProvider;
|
actionProvider;
|
||||||
|
|
||||||
function SimpleAction() {
|
function SimpleAction() {
|
||||||
@ -62,6 +63,10 @@ define(
|
|||||||
MetadataAction.key = "metadata";
|
MetadataAction.key = "metadata";
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
mockLog = jasmine.createSpyObj(
|
||||||
|
'$log',
|
||||||
|
['error', 'warn', 'info', 'debug']
|
||||||
|
);
|
||||||
actions = [
|
actions = [
|
||||||
SimpleAction,
|
SimpleAction,
|
||||||
CategorizedAction,
|
CategorizedAction,
|
||||||
@ -137,6 +142,42 @@ define(
|
|||||||
expect(provided[0].getMetadata()).toEqual("custom metadata");
|
expect(provided[0].getMetadata()).toEqual("custom metadata");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when actions throw errors during instantiation", function () {
|
||||||
|
var errorText,
|
||||||
|
provided;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
errorText = "some error text";
|
||||||
|
|
||||||
|
function BadAction() {
|
||||||
|
throw new Error(errorText);
|
||||||
|
}
|
||||||
|
|
||||||
|
provided = new ActionProvider(
|
||||||
|
[ SimpleAction, BadAction ],
|
||||||
|
mockLog
|
||||||
|
).getActions();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("logs an error", function () {
|
||||||
|
expect(mockLog.error)
|
||||||
|
.toHaveBeenCalledWith(jasmine.any(String));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports the error's message", function () {
|
||||||
|
expect(
|
||||||
|
mockLog.error.mostRecentCall.args[0].indexOf(errorText)
|
||||||
|
).not.toEqual(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("still provides valid actions", function () {
|
||||||
|
expect(provided.length).toEqual(1);
|
||||||
|
expect(provided[0].perform()).toEqual("simple");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user