Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add support for generator functions in specs #5166

Merged
merged 2 commits into from
Dec 24, 2017

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Dec 24, 2017

Summary
Fixes #2666

Easy enough to do, and brings some more feature parity with ava (https://github.com/avajs/ava/blob/965cbc65d82b12019cdf6a3257b3198dd4181b79/readme.md#generator-function-support).

Also, I was bored, and this was the lowest hanging fruit I could find with some people behind it :P I didn't update the docs much as async-await is to be preferred. Can point it out if we want it, though.

(Feel free to close this if you really don't want it, but I don't see the harm, tbh (6 lines of code))

Test plan
Integration test added. I didn't see any unit tests for the promisification happening to it already.

@codecov-io
Copy link

codecov-io commented Dec 24, 2017

Codecov Report

Merging #5166 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5166      +/-   ##
==========================================
+ Coverage   60.64%   60.65%   +0.01%     
==========================================
  Files         201      201              
  Lines        6695     6695              
  Branches        4        3       -1     
==========================================
+ Hits         4060     4061       +1     
+ Misses       2634     2633       -1     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-jasmine2/src/jasmine_async.js 33.33% <ø> (+16.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a37891...dad1e49. Read the comment docs.

@cpojer cpojer merged commit 23b7e98 into jestjs:master Dec 24, 2017
@cpojer
Copy link
Member

cpojer commented Dec 24, 2017

Good work and Merry Christmas!

@jbdemonte
Copy link
Contributor

@SimenB Any possibility to support generators in mockReturnValue (Resolve/Once)?
Idea would be to get a different value after each call to a jest.fn based on a generator, and without having to provide an implementation like:

      function* generator() {
        yield 1;
        yield 2;
        yield 3;
      }

      const iterator = generator();

      const fn = jest.fn().mockImplementation(() => iterator.next().value);
      expect(fn()).toEqual(1);
      expect(fn()).toEqual(2);
      expect(fn()).toEqual(3);
      expect(fn()).toEqual(undefined);

A cool handler would be a kinda:

jest.fn().mockReturnIteratedValue( generator() )

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for ES6 generator
5 participants