useTuitioUser test
parent
8fbe4d8be8
commit
385dd3325b
|
@ -0,0 +1,28 @@
|
||||||
|
import React from "react";
|
||||||
|
import { renderHook } from "@testing-library/react-hooks";
|
||||||
|
import { TuitioContext } from "../../src/contexts";
|
||||||
|
import { useTuitioUser } from "../../src/hooks";
|
||||||
|
|
||||||
|
describe("useTuitioUser", () => {
|
||||||
|
it("should return the userName and lastLoginDate from the TuitioContext", () => {
|
||||||
|
const testState = {
|
||||||
|
userName: "test-user",
|
||||||
|
token: {
|
||||||
|
raw: "mocked-token",
|
||||||
|
validFrom: new Date(2022, 1, 1),
|
||||||
|
validUntil: new Date(2022, 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");
|
||||||
|
expect(result.current.lastLoginDate).toEqual(new Date(2022, 1, 1));
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue