Skip to content

Instantly share code, notes, and snippets.

@ivawzh
Created May 9, 2016 10:13
Show Gist options
  • Save ivawzh/227f86f1c9368e28b119ceb58742b7bf to your computer and use it in GitHub Desktop.
Save ivawzh/227f86f1c9368e28b119ceb58742b7bf to your computer and use it in GitHub Desktop.
basic generator function
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