Skip to content

Instantly share code, notes, and snippets.

View andreivasilache's full-sized avatar
💻

Andrei VASILACHE andreivasilache

💻
View GitHub Profile
const is = (val) => ({
if: (expr) => {
if (expr)
return {
else: () => val,
is: function is() {
return {
if: () => ({ else: () => val, is }),
}
},
@andreivasilache
andreivasilache / FlushEventLoop.test.js
Last active May 18, 2021 11:59
[JEST] Wait for event loop to be cleared
const flushEventLoop = () => new Promise(resolve => setImmediate(resolve));
describe('Lorem ipsum', () => {
it('waits for load', async () => {
functionWithLotsOfMockPromises();
await waitForComponentToPaint(wrapper);
expect(/**/).toBe(true)
})
@andreivasilache
andreivasilache / WaitForComponentLoad.test.js
Last active May 18, 2021 12:00
React Jest+react-dom/test-utils wait for component to finish updating state
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
const waitForComponentToPaint = async wrapper => {
await act(async () => {
await new Promise(resolve => setTimeout(resolve));
wrapper.update();
});
};