Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(payment): PAYPAL-4550 added ability to reload script by passing an addition parameter #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/script-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ describe('ScriptLoader', () => {
.toEqual(false);
});

it('reload existing script', async () => {
await loader.loadScript('https://code.jquery.com/jquery-3.2.1.min.js');
await loader.loadScript('https://code.jquery.com/jquery-3.2.1.min.js', undefined, true);

expect(document.body.appendChild)
.toHaveBeenCalledTimes(2);
});

it('resolves promise if script is loaded', async () => {
const output = await loader.loadScript('https://code.jquery.com/jquery-3.2.1.min.js');

Expand Down
4 changes: 2 additions & 2 deletions src/script-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default class ScriptLoader {
private _requestSender: RequestSender
) {}

loadScript(src: string, options?: LoadScriptOptions): Promise<void> {
if (!this._scripts[src]) {
loadScript(src: string, options?: LoadScriptOptions, reloadScript?: boolean): Promise<void> {
if (!this._scripts[src] || !!this._scripts[src] && reloadScript) {
this._scripts[src] = new Promise((resolve, reject) => {
const script = document.createElement('script') as LegacyHTMLScriptElement;
const { async = false, attributes = {} } = options || {};
Expand Down