5663 i should be able to accept an invite even if i have an inactive workspace (#5839)
- make invitation and reset password available on every page - add a sleep after setKeyPair as tokens are sometimes not updated when redirecting to Index - refactor sleep
This commit is contained in:
35
packages/twenty-front/src/utils/__tests__/sleep.test.ts
Normal file
35
packages/twenty-front/src/utils/__tests__/sleep.test.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { sleep } from '~/utils/sleep';
|
||||
|
||||
jest.useFakeTimers();
|
||||
describe('sleep', () => {
|
||||
it('waits the provided number of milliseconds', async () => {
|
||||
const spy = jest.fn();
|
||||
const promise = sleep(1000).then(spy);
|
||||
|
||||
jest.advanceTimersByTime(999);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
jest.advanceTimersByTime(1);
|
||||
await promise; // let queued promises execute
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('call callback after the wait', async () => {
|
||||
const spy = jest.fn();
|
||||
let increment = 1;
|
||||
const callback = jest.fn((resolve) => {
|
||||
increment += 1;
|
||||
resolve();
|
||||
});
|
||||
const promise = sleep(1000, callback).then(spy);
|
||||
|
||||
jest.advanceTimersByTime(999);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
expect(increment).toEqual(1);
|
||||
jest.advanceTimersByTime(1);
|
||||
await promise; // let queued promises execute
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
expect(increment).toEqual(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user