Skip to content

Commit

Permalink
docs(mock): add doc on how to override mock return value (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
paradite authored and hustcc committed May 5, 2019
1 parent 829a870 commit e66874a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ expect(() => ctx.fill(new Path2D(), "invalid!")).toThrow(TypeError);

We try to follow the ECMAScript specification as closely as possible.

## Override default mock return value

You can override the default mock return value in your test to suit your need. For example, to override return value of `toDataURL`:

```ts
HTMLCanvasElement.prototype.toDataURL = jest
.fn()
.mockReturnValue(
'data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
);
```

## License

Expand Down

0 comments on commit e66874a

Please sign in to comment.