> For the complete documentation index, see [llms.txt](https://redux-saga-test-path.gitbook.io/redux-saga-test-path/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://redux-saga-test-path.gitbook.io/redux-saga-test-path/master.md).

# Introduction

![](/files/-L__8Zhi7tZqwRUpIPXZ)

Use `expect-to-yield` to wrap your generator object with a helper function that keeps track of each iteration and provides the expectation function `.toYieldValue(...)` to assert the expected value. When a failure happens, get access to the iteration history to figure out what is going on.

### Setup

Becoming a super hero is a fairly straight forward process:

```
$ npm install --save-dev expect-to-yield
```

### Usage

#### In your tests, wrap your iterators

```javascript
import { iteratorWithHistory as i } from 'expect-to-yield';

function* counter() {
    yield 1;
    yield 2;
    yield 3;
}
const itr = i(counter());
```

#### write your tests

```javascript
// extend expect to have `.toYieldValue(...)
import 'expect-to-yield/extend-expect';

test('the iterator works', () => {
    const itr = i(counter());
    itr.next();
    expect(itr).toYieldValue(1);
    // // this fails the test and outputs:
    // expected: 1
    // received: 2
    // history:
    // > 1: 1
    //   2: 2
    // suggestion:
    //   expect(itr).toYieldValue(1);
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redux-saga-test-path.gitbook.io/redux-saga-test-path/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
