Skip to content

Commit b2a8231

Browse files
committed
Add documentation and test for scriptId
1 parent c539106 commit b2a8231

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ A React HOC for loading 3rd party scripts asynchronously. This HOC allows you to
1818
- `callbackName`: *string* : If the script needs to call a global function when finished loading *(for example: `recaptcha/api.js?onload=callbackName`)*. Please provide the callback name here and it will be autoregistered on `window` for you.
1919
- `globalName`: *string* : Can provide the name of the global that the script attaches to `window`. Async-script will pass this as a prop to the wrapped component. *(`props[globalName] = window[globalName]`)*
2020
- `removeOnUnmount`: *boolean* **default=false** : If set to `true` removes the script tag when component unmounts.
21+
- `scriptId`: *string* : If set, it adds the following id on the script tag.
2122

2223
#### HOC Component props
2324
```js

test/async-script-loader-spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ describe("AsyncScriptLoader", () => {
139139
assert.equal(hasScript(URL), true, "Url in document");
140140
});
141141

142+
it("should add a id to the script tag", () => {
143+
const URL = "http://example.com/?has_an_id=true";
144+
const scriptId = "SOME_SCRIPT_ID";
145+
const ComponentWrapper = makeAsyncScriptLoader(URL, { scriptId })(MockedComponent);
146+
ReactTestUtils.renderIntoDocument(<ComponentWrapper />);
147+
148+
assert.equal(hasScript(URL), true, "Url in document");
149+
const script = getScript(URL);
150+
assert.equal(script.id, scriptId);
151+
});
152+
142153
it("should expose statics", done => {
143154
class MockedComponentWithStatic extends React.Component {
144155
static callsACallback(fn) {

0 commit comments

Comments
 (0)