Git Product home page Git Product logo

promise-sync's People

Contributors

slavik57 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bluelovers

promise-sync's Issues

Real sync promise

Hi @slavik57!

Very nice idea, very nice fit for the absent node API.
But actually it could’ve been done with sync or fibers so that it could be used not only for testing/debugging purposes, but for so great deals like glslify-promise etc.

Type PromiseMock<T> is not assignable to type Promise<T>

image

Hello, PromiseMock is not assignable to a variable or a parameter that expects the type Promise. The error returned by Typescript is this:

Property '[Symbol.toStringTag]' is missing in type 'PromiseMock<T>' but required in 'Promise<T>'

This makes it hard to use the promise mock in places where a real promise is expected, resulting in us having to cast the value to any. 😞

Versions

Is it expected behavior?

I've added console.log to resolve method:

public resolve(data?: T): void {
    if (!this.isPending()) {
      console.log(new Error('Cannot resolve not pending promise'));
      throw new Error('Cannot resolve not pending promise');
    }

    this._resolvedData = data;
    this._state = PromiseState.Fulfilled;

    this._resolveCallbacks(data);
  }

and then executed this code

PromiseMock.all([
    PromiseMock.resolve(1),
    PromiseMock.resolve(2),
]);

Error: Cannot resolve not pending promise was logged. Is it expected behavior that you try twice resolve one promise? And error was ignored

Returning promise from success or failure callbacks doesn't work properly

When returning promise from a success callback or a failure callback the resolved/rejected data from the returned promise is ignored, instead the previous data is passed.
The behavior should be: Wait for the promise to resolve/reject and then resolve/reject the next promise with the data/error of the returned promise

Chaining promises using PromiseMock

Hi,
First, thank you for this amazing library!

I have an issue that when I use the PromiseMock for a single method in promise chain calls, the mock does not call to the other mock.

Can you please fix this?

Thanks,
Shay

Add executor to the Promise constructor

Hi! Thanks for your great and helpful lib.

I was trying to do the following, but there wasn't a sync behaviour in my tests:

import { PromiseMock } from 'promise-sync';

const promise = new PromiseMock((res, rej) => {
  someAsyncFunction(
     result => res(result),
     error => rej(error),
   );
});

Could you add a support of constructor executor, please?

BTW, I will be happy to make a PR and add constructor executor, if you don't mind.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.