Skip to content

Commit

Permalink
Use document, add README note
Browse files Browse the repository at this point in the history
  • Loading branch information
svanherk committed Aug 10, 2023
1 parent 8c1ed3a commit ace0c50
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@ describe('my-elem', () => {

The filename and location of the resulting image will be based on the suite names and test name.

Sometimes you might be writing tests to verify a component's position within the whole viewport. For snapshots of the whole page, set up your components and pass `document` to the assertion:

```javascript
import { fixture, html } from '@brightspace-ui/testing';

describe('my-elem', () => {
describe('situation1', () => {
it('state1', async() => {
await fixture(html`<my-dialog opened></my-dialog>`);
await expect(document).to.be.golden();
});
});
});
```

#### Configuring the Snapshot Area

By default, the snapshot area will be a rectangle around the source element plus a `10px` buffer margin on each side. To use a different margin, pass it as an option:
Expand Down
2 changes: 1 addition & 1 deletion src/browser/vdiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function ScreenshotAndCompare(opts) {
}

const name = this.test.fullTitle();
const rect = this.elem === document.body ? null : this.elem.getBoundingClientRect();
const rect = this.elem === document ? null : this.elem.getBoundingClientRect();
const slowDuration = this.test.slow();
let result = await executeServerCommand('brightspace-visual-diff-compare', { name, rect, slowDuration, opts });
if (result.resizeRequired) {
Expand Down
2 changes: 1 addition & 1 deletion test/browser/element.vdiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('element-matches', () => {

it('full page', async() => {
await fixture(`<${elementTag} text="Visual Difference"></${elementTag}>`, { viewport: { width: 500, height: 500 } });
await expect(document.body).to.be.golden();
await expect(document).to.be.golden();
});
});

Expand Down

0 comments on commit ace0c50

Please sign in to comment.