tuitio-client-react/tests/hooks/useTuitioUser.test.tsx

25 lines
828 B
TypeScript

// Copyright (c) 2023 Tudor Stanciu
import React from "react";
import { renderHook } from "@testing-library/react-hooks";
import { TuitioContext } from "../../src/contexts";
import { useTuitioUser } from "../../src/hooks";
describe("useTuitioUser: positive flow", () => {
it("should return the userName from the TuitioContext", () => {
const testState = {
auth: { userName: "test-user", token: "mocked-token", validUntil: new Date(2023, 12, 31) },
configuration: {
tuitioUrl: null
}
};
const wrapper = ({ children }: { children?: React.ReactNode }) => (
<TuitioContext.Provider value={testState}>{children}</TuitioContext.Provider>
);
const { result } = renderHook(() => useTuitioUser(), { wrapper });
expect(result.current.userName).toEqual("test-user");
});
});