Skip to content

Commit

Permalink
Handle cases where the domain is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos authored Jul 22, 2020
1 parent 34b14b5 commit bf25513
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cookie.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function getBaseDomain(domain = window.document.domain): string {
export function getBaseDomain(domain = window.document.domain ?? ''): string {
const parts: string[] = domain.split('.');
const random = `___${Math.random()}`;

Expand Down
5 changes: 5 additions & 0 deletions test/cookie.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ beforeEach(() => {
});

describe('A function to detect the base domain', () => {
test('should not fail if the domain is undefined', () => {
expect(document.domain).toBeUndefined();
expect(getBaseDomain()).toBe('');
});

test('should detect the top-most domain that allows for setting cookies', () => {
let cookie = '';
cookieSetter.mockImplementation(value => {
Expand Down

0 comments on commit bf25513

Please sign in to comment.