Skip to content

Commit 023607d

Browse files
committed
updated with new proxy in async-script 0.3
1 parent c809a7d commit 023607d

File tree

6 files changed

+46
-18
lines changed

6 files changed

+46
-18
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ Other properties can be used to customised the rendering.
5050

5151
## Component API
5252

53-
**To retrieve the component, when using the wrapper, do `this.refs.recaptcha.getComponent()`**
54-
5553
The component also has some utility functions that can be called.
5654

5755
- `getValue()` returns the value of the captcha field

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"build": "node run-babel tools/build.js",
1111
"lint": "eslint src test tools webpack karma.conf.js",
12-
"test": "karma start --single-run",
12+
"test": "karma start --single-run && npm run build",
1313
"test-watch": "karma start"
1414
},
1515
"repository": {
@@ -60,6 +60,6 @@
6060
"yargs": "~3.7.1"
6161
},
6262
"dependencies": {
63-
"react-async-script": "~0.2.2"
63+
"react-async-script": "~0.3.0"
6464
}
6565
}

src/recaptcha-wrapper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ const globalName = "grecaptcha";
99
export default makeAsyncScriptLoader(ReCAPTCHA, URL, {
1010
callbackName: callbackName,
1111
globalName:globalName,
12+
exposeFuncs: ["getValue", "reset"]
1213
});

src/recaptcha.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ const ReCAPTCHA = React.createClass({
7373

7474
render() {
7575
// consume properties owned by the reCATPCHA, pass the rest to the div so the user can style it.
76+
/* eslint-disable no-unused-vars */
7677
let { sitekey, onChange, theme, type, tabindex, onExpired, ...childProps } = this.props;
78+
/* eslint-enable no-unused-vars */
7779
return (
7880
<div {...childProps} ref="captcha" />
7981
);

test/recaptcha-spec.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@ import React from "react";
22
import ReactTestUtils from "react/lib/ReactTestUtils";
33
import ReCAPTCHA from "../src/recaptcha";
44

5-
describe("ReCAPTCHA", function () {
6-
let callbackName = "onloadcallback";
7-
8-
afterEach(function () {
9-
delete window.grecaptcha;
10-
delete window.callbackName;
11-
});
12-
13-
it("Rendered Component should be a div", function () {
5+
describe("ReCAPTCHA", () => {
6+
it("Rendered Component should be a div", () => {
147
let instance = ReactTestUtils.renderIntoDocument(
15-
<ReCAPTCHA sitekey="xxx" onloadCallbackName={callbackName} />
8+
<ReCAPTCHA sitekey="xxx" />
169
);
1710
assert.equal(instance.getDOMNode().nodeName, "DIV");
1811
});
19-
it("Rendered Component should contained passed props", function () {
12+
it("Rendered Component should contained passed props", () => {
2013
let props = {
2114
className: "TheClassName",
2215
id: "superdefinedId",
@@ -28,7 +21,7 @@ describe("ReCAPTCHA", function () {
2821
assert.match(instance.getDOMNode().className, new RegExp(props.className));
2922
});
3023

31-
it("should call grecaptcha.render, when it is already loaded", function (done) {
24+
it("should call grecaptcha.render, when it is already loaded", (done) => {
3225
let grecaptchaMock = {
3326
render(node, options) {
3427
assert.isNotNull(node);
@@ -41,7 +34,7 @@ describe("ReCAPTCHA", function () {
4134
);
4235
assert.ok(instance);
4336
});
44-
it("reset, should call grecaptcha.reset with the widget id", function (done) {
37+
it("reset, should call grecaptcha.reset with the widget id", (done) => {
4538
let grecaptchaMock = {
4639
render() {
4740
return "someWidgetId";
@@ -57,7 +50,7 @@ describe("ReCAPTCHA", function () {
5750
);
5851
instance.reset();
5952
});
60-
describe("Expired", function () {
53+
describe("Expired", () => {
6154
it("should call onChange with null when response is expired");
6255
it("should call onExpired when response is expired");
6356
});

test/recaptcha-wrapper-spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from "react";
2+
import ReactTestUtils from "react/lib/ReactTestUtils";
3+
import ReCAPTCHA from "../src/recaptcha-wrapper";
4+
5+
const VALUE = "some value";
6+
const WIDGET_ID = "someWidgetId";
7+
8+
let grecaptchaMock = {
9+
render(node, options) {
10+
assert.ok(node, options);
11+
return WIDGET_ID;
12+
},
13+
14+
getResponse(widgetId) {
15+
assert.equal(widgetId, WIDGET_ID);
16+
return VALUE;
17+
}
18+
};
19+
20+
describe("ReCAPTCHAWrapper", () => {
21+
beforeEach(() => {
22+
window.grecaptcha = grecaptchaMock;
23+
});
24+
it("should proxy functions", () => {
25+
let instance = ReactTestUtils.renderIntoDocument(
26+
<ReCAPTCHA sitekey="xxx"/>
27+
);
28+
assert.ok(instance);
29+
assert.equal(instance.getValue(), VALUE);
30+
});
31+
afterEach(() => {
32+
delete window.grecaptcha;
33+
});
34+
});

0 commit comments

Comments
 (0)