-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ionic): showProgress calls don't cancel each other
- Loading branch information
1 parent
c3b5067
commit b64c0f8
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import nprogress from 'nprogress'; | ||
import { showProgress } from '.'; | ||
|
||
jest.mock('nprogress', () => ({ | ||
start: jest.fn(() => {}), | ||
done: jest.fn(() => {}), | ||
})); | ||
|
||
describe('Ionic Helpers', () => { | ||
describe('showProgress()', () => { | ||
beforeEach(jest.clearAllMocks); | ||
|
||
it('should call nprogress.start()', () => { | ||
expect(nprogress.start).toBeCalledTimes(0); | ||
expect(nprogress.done).toBeCalledTimes(0); | ||
|
||
const progress = showProgress(); | ||
|
||
expect(nprogress.start).toBeCalledTimes(1); | ||
expect(nprogress.done).toBeCalledTimes(0); | ||
|
||
progress.done(); | ||
|
||
expect(nprogress.start).toBeCalledTimes(1); | ||
expect(nprogress.done).toBeCalledTimes(1); | ||
}); | ||
|
||
it('should not call nprogress.done() when another progress has started in the meantime', async () => { | ||
const actionOne = new Promise((resolve) => { | ||
const progress = showProgress(); | ||
setTimeout(() => { | ||
progress.done(); | ||
resolve(); | ||
}, 1000); | ||
}); | ||
|
||
const actionTwo = new Promise((resolve) => { | ||
const progress = showProgress(); | ||
setTimeout(() => { | ||
progress.done(); | ||
resolve(); | ||
}, 500); | ||
}); | ||
|
||
await Promise.all([actionOne, actionTwo]); | ||
|
||
expect(nprogress.start).toBeCalledTimes(2); | ||
expect(nprogress.done).toBeCalledTimes(1); | ||
}); | ||
}); | ||
}); |