15e49cb0f9
Run Tests / test (push) Failing after 8s
- Modified Alpaca Historical Bars tests to include range parameters in API requests. - Updated test descriptions for clarity. - Added cleanup step to delete test ticker after verification in stock database tests. - Adjusted Vitest configuration to exclude test files from coverage.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
/// <reference types="vitest" />
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
import AlpacaAccountInfo from "../AlpacaAccountInfo";
|
|
|
|
describe("AlpacaAccountInfo", () => {
|
|
it("displays account info after loading", async () => {
|
|
const mockFetch = vi.fn().mockResolvedValue({
|
|
ok: true,
|
|
json: async () => ({
|
|
cash: 12345.67,
|
|
buying_power: 8000.0,
|
|
portfolio_value: 25000.0,
|
|
}),
|
|
});
|
|
globalThis.fetch = mockFetch;
|
|
|
|
render(<AlpacaAccountInfo />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText(/Trading Account/i)).toBeInTheDocument();
|
|
});
|
|
expect(screen.getByText(/Cash/)).toBeInTheDocument();
|
|
expect(screen.getByText(/Buying Power/)).toBeInTheDocument();
|
|
expect(screen.getByText(/Portfolio Value/)).toBeInTheDocument();
|
|
});
|
|
|
|
it("displays error when fetch fails", async () => {
|
|
const mockFetch = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
globalThis.fetch = mockFetch;
|
|
|
|
render(<AlpacaAccountInfo />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText(/Network error/i)).toBeInTheDocument();
|
|
});
|
|
});
|
|
}); |