1. flush-promises
Flush promises in tests
flush-promises
Package: flush-promises
Created by: kentor
Last modified: Sat, 18 Jun 2022 02:27:25 GMT
Version: 1.0.2
License: MIT
Downloads: 1,118,233
Repository: https://github.com/kentor/flush-promises

Install

npm install flush-promises
yarn add flush-promises

flush-promises

Build Status npm

Flush all pending resolved promise handlers. Useful in tests.

example with async/await

 const flushPromises = require('flush-promises');

test('flushPromises', async () => {
  let a;
  let b;

  Promise.resolve().then(() => {
    a = 1;
  }).then(() => {
    b = 2;
  })

  await flushPromises();

  expect(a).toBe(1);
  expect(b).toBe(2);
});

TypeScript

 import * as flushPromises from "flush-promises";

test("flushPromises", async () => {
  let a;
  let b;
 
  Promise.resolve().then(() => {
    a = 1;
  }).then(() => {
    b = 2;
  });
 
  await flushPromises();
 
  expect(a).toBe(1);
  expect(b).toBe(2);
});

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin