Skip to content

Commit

Permalink
docs(clipregion): fix docs regarding clip region
Browse files Browse the repository at this point in the history
  • Loading branch information
jtenner authored and hustcc committed Nov 27, 2019
1 parent a3b7b85 commit 80f24aa
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ We try to follow the ECMAScript specification as closely as possible.

## Snapshots

There are multiple ways to validate canvas state. There are currently three `static` methods attached
to the `CanvasRenderingContext2D` class. The first way to use this feature is by using the `__getEvents`
method.
There are multiple ways to validate canvas state using snapshots. There are currently three methods
attached to the `CanvasRenderingContext2D` class. The first way to use this feature is by using the
`__getEvents` method.

```ts
/**
Expand Down Expand Up @@ -129,7 +129,7 @@ const path = ctx.__getPath();
expect(path).toMatchSnapshot();
```

The third way is to inspect all of the success draw calls submitted to the context.
The third way is to inspect all of the successful draw calls submitted to the context.

```ts
ctx.drawImage(img, 0, 0);
Expand All @@ -152,6 +152,17 @@ ctx.__clearEvents();
ctx.__clearDrawCalls();
```

Finally, it's possible to inspect the clipping region calls by using the `__getClippingRegion`
function.

```ts
const clippingRegion = ctx.__getClippingRegion();
expect(clippingRegion).toMatchSnapshot();
```

The clipping region cannot be cleared because it's based on the stack values and when the `.clip()`
function is called.

## 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`:
Expand Down

0 comments on commit 80f24aa

Please sign in to comment.