Skip to content

Commit 60e1b6a

Browse files
committed
create dummy location
1 parent 83f1f30 commit 60e1b6a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import type { Options } from '@emailjs/browser/es/types/Options';
88
import { EmailJSResponseStatus } from '@emailjs/browser/es/models/EmailJSResponseStatus';
99
import { createReactNativeStorage } from './utils/createReactNativeStorage/createReactNativeStorage';
10+
import { createLocation } from './utils/createLocation/createLocation';
1011

1112
/**
1213
* EmailJS global SDK config
@@ -37,6 +38,8 @@ const send = async (
3738
templateParams?: Record<string, unknown>,
3839
options?: Options,
3940
): Promise<EmailJSResponseStatus> => {
41+
createLocation();
42+
4043
return emailjsSend(serviceID, templateID, templateParams, {
4144
storageProvider: createReactNativeStorage(),
4245
...options,
@@ -57,6 +60,8 @@ const sendForm = async (
5760
form: string | HTMLFormElement,
5861
options?: Options,
5962
): Promise<EmailJSResponseStatus> => {
63+
createLocation();
64+
6065
return emailjsSendForm(serviceID, templateID, form, {
6166
storageProvider: createReactNativeStorage(),
6267
...options,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { it, expect } from '@jest/globals';
2+
import { createLocation } from './createLocation';
3+
4+
it('test location', () => {
5+
createLocation();
6+
expect(location).toEqual(window.location);
7+
});
8+
9+
it('create default location', () => {
10+
// @ts-expect-error: remove location
11+
global.location = undefined;
12+
createLocation();
13+
expect(location).toEqual({ pathname: 'default' });
14+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const createLocation = () => {
2+
window.location = window.location || {
3+
pathname: 'default',
4+
};
5+
};

0 commit comments

Comments
 (0)