added context hook to allow the override of the default binder

This commit is contained in:
Sebastian Sdorra
2020-02-19 09:47:52 +01:00
parent fac46d636f
commit 041a999a01
4 changed files with 51 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
import useBinder, { BinderContext } from "./useBinder";
import { Binder } from "./binder";
import { mount } from "enzyme";
import "@scm-manager/ui-tests/enzyme";
import React from "react";
describe("useBinder tests", () => {
const BinderName = () => {
const binder = useBinder();
return <>{binder.name}</>;
};
it("should return default binder", () => {
const rendered = mount(<BinderName />);
expect(rendered.text()).toBe("default");
});
it("should return binder from context", () => {
const binder = new Binder("from-context");
const app = (
<BinderContext.Provider value={binder}>
<BinderName />
</BinderContext.Provider>
);
const rendered = mount(app);
expect(rendered.text()).toBe("from-context");
});
});