Skip to content

Commit 6f7f21b

Browse files
committed
unit test
Signed-off-by: Pujal <[email protected]>
1 parent f38383b commit 6f7f21b

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

packages/zowe-explorer/__tests__/__unit__/trees/dataset/ZoweDatasetNode.unit.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { SettingsConfig } from "../../../../src/configuration/SettingsConfig";
4747
import { MockedProperty } from "../../../__mocks__/mockUtils";
4848
import { AuthUtils } from "../../../../src/utils/AuthUtils";
4949
import { ImperativeError } from "@zowe/imperative";
50+
import { error } from "console";
5051

5152
// Missing the definition of path module, because I need the original logic for tests
5253
jest.mock("fs");
@@ -1912,22 +1913,19 @@ describe("ZoweDatasetNode Unit Tests - listMembersInRange()", () => {
19121913
});
19131914
it("returns an empty list, if listMembersInRange throws a 404 error", async () => {
19141915
const pdsNode = new ZoweDatasetNode({
1915-
label: "PDS.ERROR",
1916+
label: "PDS.404",
19161917
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
19171918
contextOverride: Constants.DS_PDS_CONTEXT,
19181919
});
19191920

1920-
const notFoundError = new imperative.ImperativeError({
1921-
msg: "Datasets not cataloged",
1922-
errorCode: "404",
1923-
});
1924-
1925-
jest.spyOn(pdsNode, "listMembers").mockImplementationOnce(async () => {
1926-
throw notFoundError;
1927-
});
1921+
jest.spyOn(pdsNode, "listMembers").mockRejectedValue(
1922+
new imperative.ImperativeError({
1923+
msg: "Dataset not cataloged",
1924+
errorCode: `${imperative.RestConstants.HTTP_STATUS_404}`,
1925+
})
1926+
);
19281927

19291928
const result = await (pdsNode as any).listMembersInRange(undefined, 2);
1930-
console.log("HELLO" + result.items);
19311929
expect(result).toStrictEqual({ items: [] });
19321930
});
19331931
});

packages/zowe-explorer/src/trees/dataset/ZoweDatasetNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ export class ZoweDatasetNode extends ZoweTreeNode implements IZoweDatasetTreeNod
834834

835835
await this.listMembers(responses, { attributes: true, start, maxLength: start ? limit + 1 : limit });
836836
} catch (err) {
837-
if (err.errorCode === "404") {
837+
if (err instanceof imperative.ImperativeError && err.errorCode === `${imperative.RestConstants.HTTP_STATUS_404}`) {
838838
return {
839839
items: [],
840840
};

0 commit comments

Comments
 (0)