Skip to content

Commit

Permalink
feat(useFetchye): headless [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael A Tomcal committed Sep 15, 2020
1 parent a847d60 commit 0c7ff61
Show file tree
Hide file tree
Showing 17 changed files with 612 additions and 360 deletions.
92 changes: 0 additions & 92 deletions __tests__/FetchyeContext.spec.jsx

This file was deleted.

4 changes: 2 additions & 2 deletions __tests__/computeKey.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ describe('computeKey', () => {
computeKey(() => {
throw new Error('error');
}, {})
).toBeFalsy();
).toEqual(false);
});
it('should return false if key func returns false', () => {
expect(computeKey(() => false, {})).toBeFalsy();
expect(computeKey(() => false, {})).toEqual(false);
});
});
4 changes: 2 additions & 2 deletions __tests__/defaultMapOptionsToKey.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import { defaultMapOptionsToKey } from '../src/defaultMapOptionsToKey';

describe('defaultMapOptionsToKey', () => {
it('should return an object without passed lazy or mapOptionsToKey', () => {
expect(defaultMapOptionsToKey({ lazy: true, mapOptionsToKey: () => {}, method: 'POST' }))
it('should return an object without passed defer or mapOptionsToKey', () => {
expect(defaultMapOptionsToKey({ defer: true, mapOptionsToKey: () => {}, method: 'POST' }))
.toMatchInlineSnapshot(`
Object {
"method": "POST",
Expand Down
1 change: 0 additions & 1 deletion __tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('index', () => {
it('should return public methods', () => {
expect(Object.keys(fetchye).sort()).toMatchInlineSnapshot(`
Array [
"FetchyeReduxProvider",
"makeServerFetchye",
"useFetchye",
]
Expand Down
10 changes: 5 additions & 5 deletions __tests__/isLoading.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import { isLoading } from '../src/isLoading';

describe('defaultMapOptionsToKey', () => {
it('should return true if loading cache true', () => {
expect(isLoading(true, {}, {})).toBeTruthy();
expect(isLoading(true, {}, {})).toEqual(true);
});
it('should return true if first render is true', () => {
expect(isLoading(false, { current: true }, {})).toBeTruthy();
expect(isLoading(false, { current: true }, {})).toEqual(true);
});
it('should return false if first render is true and lazy is true', () => {
expect(isLoading(false, { current: true }, { lazy: true })).toBeFalsy();
it('should return false if first render is true and defer is true', () => {
expect(isLoading(false, { current: true }, { defer: true })).toEqual(false);
});
it('should return false if all args are false', () => {
expect(isLoading(false, { current: false }, { lazy: false })).toBeFalsy();
expect(isLoading(false, { current: false }, { defer: false })).toEqual(false);
});
});
54 changes: 54 additions & 0 deletions __tests__/queryHelpers.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2020 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import {
isLoading, coerceSsrField,
} from '../src/queryHelpers';

describe('isLoading', () => {
it('should return true if loading cache true', () => {
expect(isLoading({
loading: true, data: undefined, numOfRenders: 2, options: {},
})).toEqual(true);
});
it('should return true if first render is true', () => {
expect(isLoading({
loading: false, data: undefined, numOfRenders: 1, options: { },
})).toEqual(true);
});
it('should return false if first render is true and defer is true', () => {
expect(isLoading({
loading: false, data: undefined, numOfRenders: 1, options: { defer: true },
})).toEqual(false);
});
it('should return false if all args are false', () => {
expect(isLoading({
loading: false, numOfRenders: 2, options: { defer: false },
})).toEqual(false);
});
});

describe('coerceSsrField', () => {
it('should return stringified error', () => {
expect(coerceSsrField(new Error('Fake Error'))).toEqual('Error: Fake Error');
});
it('should return null if undefined', () => {
expect(coerceSsrField(undefined)).toEqual(null);
});
it('should pass through field if not error or undefined', () => {
expect(coerceSsrField('field')).toEqual('field');
});
});

0 comments on commit 0c7ff61

Please sign in to comment.