Skip to content

Commit

Permalink
test: improve observer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 23, 2021
1 parent a70799d commit 2c76206
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/platform/mutation-observer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,34 @@ <h1>MutationObserver</h1>
targetNode.textContent = '';
}
});

document.body.className = 'completed';
})();
</script>
<script>
(function () {
let step = 0;
function nextStep() {
step++;
const elm = document.getElementById('testMutationObserver');
elm.classList.add('step' + step);
const testStep = document.getElementById('testStep');
testStep.textContent = 'step' + step;
}

const targetNode = document.getElementById('target');
const buttonAttr = document.getElementById('buttonAttr');

buttonAttr.addEventListener('click', () => {
targetNode.setAttribute('mutate', rand());
nextStep();
});

const buttonChildList = document.getElementById('buttonChildList');
buttonChildList.addEventListener('click', () => {
targetNode.textContent = '';
targetNode.appendChild(document.createTextNode(rand()));
nextStep();
});

function rand() {
Expand All @@ -131,6 +144,8 @@ <h1>MutationObserver</h1>
</li>
</ul>

<div id="testStep"></div>

<p><a href="/">All Tests</a></p>
</body>
</html>
4 changes: 4 additions & 0 deletions tests/platform/mutation-observer/mutation-observer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { test, expect } from '@playwright/test';
test('mutation-observer', async ({ page }) => {
await page.goto('/platform/mutation-observer/');

await page.waitForSelector('.completed');

const buttonObserve = page.locator('#buttonObserve');
const buttonAttr = page.locator('#buttonAttr');
const buttonChildList = page.locator('#buttonChildList');
Expand All @@ -18,9 +20,11 @@ test('mutation-observer', async ({ page }) => {
await buttonObserve.click();

await buttonAttr.click();
await page.waitForSelector('.step1');
await expect(testMutationObserver).toHaveText('attributes');

await buttonChildList.click();
await page.waitForSelector('.step2');
await expect(testMutationObserver).toHaveText('childList');

await buttonObserve.click();
Expand Down
2 changes: 1 addition & 1 deletion tests/platform/resize-observer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h1>ResizeObserver</h1>
nextStep();
});

document.body.className = 'completed'
document.body.className = 'completed';
})();
</script>
</li>
Expand Down

1 comment on commit 2c76206

@vercel
Copy link

@vercel vercel bot commented on 2c76206 Oct 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.