Skip to content

Instantly share code, notes, and snippets.

@Xotabu4
Last active February 28, 2025 10:44
Show Gist options
  • Save Xotabu4/50fd6d208217d4bdcd5afc6dad87e84e to your computer and use it in GitHub Desktop.
Save Xotabu4/50fd6d208217d4bdcd5afc6dad87e84e to your computer and use it in GitHub Desktop.
mixin.test.ts
import test, { Page } from "@playwright/test";
const myTest = test.extend<{
whiteLabel: boolean;
app: {
homePage: ReturnType<typeof HomePage>;
};
}>({
whiteLabel: [false, { option: true }],
app: async ({ page, whiteLabel }, use) => {
const app = {
homePage: {
...HomePage(page),
...(whiteLabel ? WhiteLabelMixin(page) : {}),
},
};
await use(app);
},
});
const WhiteLabelMixin = (page: Page) => ({
createQuote() {
console.log("create quote");
console.log("submit quote");
console.log("expire quote");
},
});
const HomePage = (page: Page) => ({
createQuote() {
console.log("create quote");
console.log("expire quote");
},
doSomethingMore() {
console.log("do something more");
},
});
myTest.describe(() => {
myTest.use({
whiteLabel: false,
});
myTest("no white label", async ({ app }) => {
app.homePage.createQuote();
});
});
myTest.describe(() => {
myTest.use({
whiteLabel: true,
});
myTest("white label", async ({ app }) => {
app.homePage.createQuote();
});
});
Running 2 tests using 1 worker
create quote
expire quote
✓ 1 [shared-behaviors] › example.test.ts:44:3 › no white label (38ms)
create quote
submit quote
expire quote
✓ 2 [shared-behaviors] › example.test.ts:54:3 › white label (30ms)
2 passed (584ms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment