Skip to content

Commit

Permalink
test(__tests__/getters): adding memoized number getters
Browse files Browse the repository at this point in the history
adding tests for the memoized number getters

re #1108
  • Loading branch information
schie authored and mikehardy committed Nov 1, 2020
1 parent 5003f1e commit 23e4b32
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions __tests__/getters.test.ts
Expand Up @@ -90,3 +90,68 @@ describe('string getters', () => {
}
);
});

const memoizedNumberGetters = [
'getApiLevel',
'getPreviewSdkInt',
'getFirstInstallTime',
'getLastUpdateTime',
'getTotalMemory',
'getMaxMemory',
].map(makeTable);

describe('number getters', () => {
describe.each(memoizedNumberGetters)(
'%s*',
(_name, asyncGetter, syncGetter, asyncNativeGetter, syncNativeGetter) => {
beforeEach(() => {
clearMemo();
Platform.OS = 'android';
asyncNativeGetter.mockClear();
syncNativeGetter.mockClear();
});

it('should have an async version', () => {
expect(typeof asyncGetter).toBe('function');
});

it('should have a sync version', () => {
expect(typeof syncGetter).toBe('function');
});

it('should call native async module function', async () => {
const resp = await asyncGetter();
expect(resp).toEqual(-1);
expect(asyncNativeGetter).toHaveBeenCalled();
});

it('should call native sync module function', () => {
const resp = syncGetter();
expect(resp).toEqual(-1);
expect(syncNativeGetter).toHaveBeenCalled();
});

it('should not call native sync module function on unsupported OS', () => {
Platform.OS = 'GLaDOS' as any; // setting OS to something that won't match anything
const resp = syncGetter();
expect(resp).toEqual(-1);
expect(syncNativeGetter).not.toHaveBeenCalled();
});

it('should not call native async module function on unsupported OS', async () => {
Platform.OS = 'GLaDOS' as any; // setting OS to something that won't match anything
const resp = await asyncGetter();
expect(resp).toEqual(-1);
expect(asyncNativeGetter).not.toHaveBeenCalled();
});

it('should use memoized value if there exists one', async () => {
const resp = await asyncGetter();
const resp2 = syncGetter();
expect(resp).toBe(resp2);
expect(asyncNativeGetter).toHaveBeenCalled();
expect(syncNativeGetter).not.toHaveBeenCalled();
});
}
);
});

0 comments on commit 23e4b32

Please sign in to comment.