Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Use object to export internal functions on test
Browse files Browse the repository at this point in the history
  • Loading branch information
lapanti committed Jun 19, 2017
1 parent dab0e28 commit f98d367
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/__specs__/cookies.spec.ts
@@ -1,4 +1,5 @@
import cookies, { CookieError, cookieSupport } from '../cookies';
import cookies, { CookieError, priv } from '../cookies';
const { checkCookieSupport } = priv as any;

test('Cookies', () => {
describe('get', () => {
Expand Down Expand Up @@ -27,7 +28,7 @@ test('Cookies', () => {
});

describe('checkCookieSupport', () => {
expect(cookieSupport()).toBeTruthy();
expect(checkCookieSupport()).toBeTruthy();
});
});

Expand Down Expand Up @@ -78,7 +79,7 @@ test('Cookies in server', () => {
});

describe('checkCookieSupport', () => {
expect(cookieSupport()).toThrow(CookieError);
expect(cookieSupport({ silent: true })).toBeFalsy();
expect(checkCookieSupport()).toThrow(CookieError);
expect(checkCookieSupport({ silent: true })).toBeFalsy();
});
});
3 changes: 2 additions & 1 deletion src/cookies.ts
Expand Up @@ -13,7 +13,6 @@ const checkCookieSupport = (opts?: ICookieOptions): boolean => {
}
return typeof document !== 'undefined';
};
export const cookieSupport = process && process.env && process.env.NODE_ENV === 'test' ? checkCookieSupport : null;

const write = (name: string, value: string, opts?: ICookieOptions): boolean => {
if (checkCookieSupport(opts)) {
Expand All @@ -39,4 +38,6 @@ const cookies = {
remove: (name: string, opts?: ICookieOptions): boolean => write(name, '', Object.assign({ days: -1 }, opts)),
};

export const priv = process && process.env && process.env.NODE_ENV === 'test' ? { checkCookieSupport } : null;

export default cookies;

0 comments on commit f98d367

Please sign in to comment.