slavik57 / promise-sync Goto Github PK
View Code? Open in Web Editor NEWpromise-sync - Synchronous promise stub
License: MIT License
promise-sync - Synchronous promise stub
License: MIT License
PromiseMock.d.ts has a following line:
readonly state: PromiseState;
Readonly properties will be available starting from typescript 2.0 microsoft/TypeScript#6532
So now there are compilation errors at this line.
Added PR: #9
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.
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
. 😞
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
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
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.