Created
May 9, 2016 10:13
-
-
Save ivawzh/227f86f1c9368e28b119ceb58742b7bf to your computer and use it in GitHub Desktop.
basic generator function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('generator function works', () => { | |
function* anotherGenerator(i) { | |
yield i + 1 | |
yield i + 2 | |
yield i + 3 | |
} | |
function* generator(i){ | |
yield i | |
yield* anotherGenerator(i) | |
yield i + 10 | |
} | |
const gen = generator(10) | |
expect(gen.next()).to.eql({value: 10, done: false}) | |
expect(gen.next().value).to.eq(11) | |
expect(gen.next().value).to.eq(12) | |
expect(gen.next().value).to.eq(13) | |
expect(gen.next().value).to.eq(20) | |
expect(gen.next()).to.eql({value: undefined, done: true}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment