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

Does jasmine 2.6.0 not support ES7 async await functions? #1350

Closed
thepiyush13 opened this issue May 8, 2017 · 3 comments
Closed

Does jasmine 2.6.0 not support ES7 async await functions? #1350

thepiyush13 opened this issue May 8, 2017 · 3 comments

Comments

@thepiyush13
Copy link

I am trying to use Jasmine to test functions that use ES7 async await features. Jasmine although works for promises and async functions, it fails for ES7 async function. For example:

describe("async-test", () => {
  it('should run test', (async function(done) {
     var x = await fakeRequest();
     expect(x).toBeDefined();
     done();
  }));
 
});

async function fakeRequest() {
     let result = await another_request();
     return result;
}

async function another_request(){
    // returns promise resolution or some async function call return
}

it always gives this error:

async-test
    ✖ should run test
      PhantomJS 2.1.1 (Mac OS X 0.0.0)
    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. in config/karma-shim.js (line 98794)
    ZoneAwareError@webpack:///~/zone.js/dist/zone.js:999:0 <- config/karma-shim.js:98794:28

How can I make it work. Jasmine works when I am only dealing with promises but as soon as ES7 come in, it stops working. How can I make it work with functions that use ES7 features?

I am running
"jasmine-core": "^2.6.0","karma": "^1.6.0", "typescript": "~2.2.2" and Node 7.10.0

@slackersoft
Copy link
Member

Jasmine never truly supported async functions, since it would never actually await them. In 2.6, Jasmine will now throw an Error if something that is not a function is passed into it because users would accidentally pass in an async function() without a done parameter and Jasmine would just execute it as if it was synchronous, moving on to the next spec at the first await.

We're looking into fully supporting promises (via #1270 or something like it), which would then also hopefully allow async/await to work as expected.

@rdy
Copy link

rdy commented May 18, 2017

I've built the following support here
https://github.com/rdy/jasmine-async-suite

It can be added as long as you are running jasmine in a javascript environment that supports promises.

@slackersoft
Copy link
Member

The plan right now is to try to get Promise support, along with async functions into Jasmine itself in 2.7. With some of the issues from 2.6, I haven't been able to get too much further into this though.

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

3 participants