Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/commands/network/setNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class NetworkActions extends BaseAction {
async setNetwork(networkName?: string): Promise<void> {
const entries = this.getNetworkEntries();

if (networkName || networkName === "") {
if (networkName) {
const selectedNetwork = entries.find(n =>
n.alias === networkName || (n.type === "built-in" && n.name === networkName),
);
Expand Down
14 changes: 10 additions & 4 deletions tests/actions/setNetwork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ describe("NetworkActions", () => {
expect(networkActions["succeedSpinner"]).not.toHaveBeenCalled();
});

test("setNetwork method fails for empty network name", async () => {
test("setNetwork method prompts user when an empty network name is provided", async () => {
vi.mocked(inquirer.prompt).mockResolvedValue({
selectedNetwork: "localnet",
});

await networkActions.setNetwork("");

expect(networkActions["failSpinner"]).toHaveBeenCalledWith("Network not found");
expect(networkActions["writeConfig"]).not.toHaveBeenCalled();
expect(networkActions["succeedSpinner"]).not.toHaveBeenCalled();
expect(inquirer.prompt).toHaveBeenCalled();
expect(networkActions["writeConfig"]).toHaveBeenCalledWith("network", "localnet");
expect(networkActions["succeedSpinner"]).toHaveBeenCalledWith(
`Network successfully set to ${localnet.name}`,
);
});

test("setNetwork method prompts user when no network name provided", async () => {
Expand Down
Loading