forked from dozoisch/react-google-recaptcha
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecaptcha-wrapper.spec.js
More file actions
38 lines (34 loc) · 979 Bytes
/
recaptcha-wrapper.spec.js
File metadata and controls
38 lines (34 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from "react";
import ReactTestUtils from "react-dom/test-utils";
import ReCAPTCHA from "../src/recaptcha-wrapper";
const VALUE = "some value";
const WIDGET_ID = "someWidgetId";
const grecaptchaMock = {
render(node, options) {
expect(node).toBeTruthy();
expect(options).toBeTruthy();
return WIDGET_ID;
},
getResponse(widgetId) {
expect(widgetId).toBe(WIDGET_ID);
return VALUE;
},
};
describe("ReCAPTCHAWrapper", () => {
beforeEach(() => {
window.grecaptcha = grecaptchaMock;
});
afterEach(() => {
delete window.grecaptcha;
});
it("should be wrapped properly", () => {
expect(ReCAPTCHA.displayName).toBe("AsyncScriptLoader(ReCAPTCHA)");
});
it("should proxy functions", () => {
const ReCaptchaRef = React.createRef();
ReactTestUtils.renderIntoDocument(
<ReCAPTCHA sitekey="xxx" ref={ReCaptchaRef} onChange={jest.fn()} />,
);
expect(ReCaptchaRef.current.getValue()).toBe(VALUE);
});
});