Skip to content

Commit

Permalink
Allow LogBoxLog-test to work with native promises
Browse files Browse the repository at this point in the history
Differential Revision: D39418413

fbshipit-source-id: 7b4c96c62ada4ef7cd5231b305c926068026df38
  • Loading branch information
robhogan authored and facebook-github-bot committed Sep 11, 2022
1 parent 4c4f967 commit ffe0cd9
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Libraries/LogBox/Data/__tests__/LogBoxLog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const createStack = (methodNames: Array<string>) =>
methodName,
}));

// Adds a new task to the end of the microtask queue, so that awaiting this
// function will run all queued immediates
const runMicrotasks = async () => {};

describe('LogBoxLog', () => {
beforeEach(() => {
jest.resetModules();
Expand Down Expand Up @@ -132,7 +136,7 @@ describe('LogBoxLog', () => {
expect(getLogBoxSymbolication().symbolicate).not.toBeCalled();
});

it('updates when symbolication finishes', () => {
it('updates when symbolication finishes', async () => {
const log = getLogBoxLog();

const callback = jest.fn();
Expand All @@ -141,7 +145,7 @@ describe('LogBoxLog', () => {
expect(callback).toBeCalledWith('PENDING');
expect(getLogBoxSymbolication().symbolicate).toBeCalled();

jest.runAllTicks();
await runMicrotasks();

expect(callback).toBeCalledTimes(2);
expect(callback).toBeCalledWith('COMPLETE');
Expand All @@ -156,13 +160,14 @@ describe('LogBoxLog', () => {
getLogBoxSymbolication().symbolicate.mockClear();

log.symbolicate(callback);
jest.runAllTicks();

await runMicrotasks();

expect(callback).toBeCalledTimes(0);
expect(getLogBoxSymbolication().symbolicate).not.toBeCalled();
});

it('updates when symbolication fails', () => {
it('updates when symbolication fails', async () => {
const error = new Error('...');
getLogBoxSymbolication().symbolicate.mockImplementation(async stack => {
throw error;
Expand All @@ -176,7 +181,7 @@ describe('LogBoxLog', () => {
expect(callback).toBeCalledWith('PENDING');
expect(getLogBoxSymbolication().symbolicate).toBeCalled();

jest.runAllTicks();
await runMicrotasks();

expect(callback).toBeCalledTimes(2);
expect(callback).toBeCalledWith('FAILED');
Expand All @@ -191,7 +196,8 @@ describe('LogBoxLog', () => {
getLogBoxSymbolication().symbolicate.mockClear();

log.symbolicate(callback);
jest.runAllTicks();

await runMicrotasks();

expect(callback).toBeCalledTimes(0);
expect(getLogBoxSymbolication().symbolicate).not.toBeCalled();
Expand Down Expand Up @@ -221,7 +227,7 @@ describe('LogBoxLog', () => {
expect(getLogBoxSymbolication().symbolicate).not.toBeCalled();
});

it('retry updates when symbolication finishes', () => {
it('retry updates when symbolication finishes', async () => {
const log = getLogBoxLog();

const callback = jest.fn();
Expand All @@ -230,7 +236,7 @@ describe('LogBoxLog', () => {
expect(callback).toBeCalledWith('PENDING');
expect(getLogBoxSymbolication().symbolicate).toBeCalled();

jest.runAllTicks();
await runMicrotasks();

expect(callback).toBeCalledTimes(2);
expect(callback).toBeCalledWith('COMPLETE');
Expand All @@ -251,7 +257,7 @@ describe('LogBoxLog', () => {
expect(getLogBoxSymbolication().symbolicate).not.toBeCalled();
});

it('retry updates when symbolication fails', () => {
it('retry updates when symbolication fails', async () => {
const error = new Error('...');
getLogBoxSymbolication().symbolicate.mockImplementation(async stack => {
throw error;
Expand All @@ -265,7 +271,7 @@ describe('LogBoxLog', () => {
expect(callback).toBeCalledWith('PENDING');
expect(getLogBoxSymbolication().symbolicate).toBeCalled();

jest.runAllTicks();
await runMicrotasks();

expect(callback).toBeCalledTimes(2);
expect(callback).toBeCalledWith('FAILED');
Expand All @@ -289,7 +295,7 @@ describe('LogBoxLog', () => {
expect(callback).toBeCalledWith('PENDING');
expect(getLogBoxSymbolication().symbolicate).toBeCalled();

jest.runAllTicks();
await runMicrotasks();

expect(callback).toBeCalledTimes(2);
expect(callback).toBeCalledWith('COMPLETE');
Expand Down

0 comments on commit ffe0cd9

Please sign in to comment.