Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kata 76 - Promise Creation - doesn't wrok in TDDbin #35

Open
rr326 opened this issue Sep 21, 2016 · 5 comments
Open

Kata 76 - Promise Creation - doesn't wrok in TDDbin #35

rr326 opened this issue Sep 21, 2016 · 5 comments

Comments

@rr326
Copy link

rr326 commented Sep 21, 2016

I couldn't get the kata to resolve. So I checked out the original checkin (which should pass). Tests 2&3 don't work.

But pasting it into Chrome debugger, it works properly (as it should).

Test

  describe('extending a `Promise`', function() {
    it('is possible', function() {
      class MyPromise extends Promise {}
      const promise = new MyPromise(resolve => resolve());

      promise
        .then(() => done())
        .catch(e => done(new Error('Expected to resolve, but failed with: ' + e)));
    });
    it('must call `super()` in the constructor if it wants to inherit/specialize the behavior', function() {
      // WARNING: this example doesn't fulfill the Liskov principle
      class ResolvingPromise extends Promise {
        constructor() {
          super(resolve => resolve());
        }
      }

      return new ResolvingPromise();
    });
  });

Returns

extending a Promise
is possible ‣
TypeError: # is not a promise
at new MyPromise (eval at runSpecs (http://tddbin.com/mocha/spec-runner.js:95056:7), :28:81)
at eval (eval at runSpecs (http://tddbin.com/mocha/spec-runner.js:95056:7), :34:21)
at r (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:9112)
at r.o.run (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:9812)
at o.runTest (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:13250)
at http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:13824
at r (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:12787)
at http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:12763
at n (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:12554)
at http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:12618
must call super() in the constructor if it wants to inherit/specialize the behavior ‣
TypeError: # is not a promise
at new ResolvingPromise (eval at runSpecs (http://tddbin.com/mocha/spec-runner.js:95056:7), :53:88)
at eval (eval at runSpecs (http://tddbin.com/mocha/spec-runner.js:95056:7), :61:14)
at r (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:9112)
at r.o.run (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:9812)
at o.runTest (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:13250)
at http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:13824
at r (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:12787)
at http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:12763
at n (http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:12554)
at http://cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js:2:12618

In Chrome

done = (retval) => `done ${retval}`
(retval) => `done ${retval}`
      class MyPromise extends Promise {}
      const promise = new MyPromise(resolve => resolve());

      promise
        .then(() => done())
        .catch(e => done(new Error('Expected to resolve, but failed with: ' + e)));

Returns

Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: "done undefined"}

@fourcolors
Copy link

Verified on my end.

@ragmha
Copy link

ragmha commented Jan 17, 2017

Same here

@mii9000
Copy link

mii9000 commented Sep 13, 2018

For me it works on Chrome if Transpile to ES5 is turned off. Would like to know the reason though.

@sandbox992
Copy link

sandbox992 commented Jan 13, 2019

Have another problem:

describe('extending a Promise', function() {
it('using class X extends Promise{} is possible', function(done) {
class MyPromise extends Promise {}
const promise = new MyPromise(resolve => resolve());
promise
.then(() => done())
.catch(e => done(new Error('Expected to resolve, but failed with: ' + e)));
});
it('must call super() in the constructor if it wants to inherit/specialize the behavior', function() {
class ResolvingPromise extends Promise {
constructor() {
super()
}
}
return new ResolvingPromise(resolve => resolve());
});
});

Returns:
Method Promise.prototype.then called on incompatible receiver #
Method Promise.prototype.then called on incompatible receiver #
for first and second tasks relatively

Similar problem(not mine, just found):
https://stackoverflow.com/questions/40404028/working-through-es6-katas-extending-promises

@wolframkriesing
Copy link
Collaborator

I was struggling to understand this issue. I played around with the kata, but I dont know what is meant that it doesnt work. If there is still interest, I would be keen on learning what the problem was (or still is).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants