Skip to content

Commit 7981757

Browse files
committed
test: address comments
1 parent e223a89 commit 7981757

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

e2e/fixtures/assertions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {expect} from '@playwright/test';
2+
3+
/** Asserts that a condition is truthy while narrowing its type */
4+
export default function assert(
5+
condition: any,
6+
message?: string,
7+
): asserts condition {
8+
expect(condition, message).toBeTruthy();
9+
}

e2e/fixtures/cart-utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {expect, Locator, Page} from '@playwright/test';
2+
import assert from './assertions';
23

34
const CART_ID_PREFIX = 'gid://shopify/Cart/';
45

@@ -30,14 +31,13 @@ export class CartUtil {
3031
const nextValue = enabledOptionValues.find(
3132
(value) => value !== initialValue,
3233
);
33-
if (!nextValue) {
34-
throw new Error(
35-
'Expected option select to have at least two different values',
36-
);
37-
}
34+
assert(
35+
nextValue,
36+
'Expected option select to have at least two different values',
37+
);
3838

3939
await optionSelect.selectOption(nextValue);
40-
await expect.poll(async () => optionSelect.inputValue()).toBe(nextValue);
40+
await expect(optionSelect).toHaveValue(nextValue);
4141

4242
return {optionName, nextValue};
4343
}

e2e/specs/recipes/custom-cart-method.spec.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {test, expect, setRecipeFixture} from '../../fixtures';
2+
import assert from '../../fixtures/assertions';
23
import {CartUtil} from '../../fixtures/cart-utils';
34

45
setRecipeFixture({
@@ -70,28 +71,20 @@ test.describe('Custom Cart Method Recipe', () => {
7071
name: KNOWN_PRODUCT_WITH_VARIANTS.name,
7172
});
7273
const initialUrl = await productLink.getAttribute('href');
73-
expect(initialUrl).toBeTruthy();
74+
assert(initialUrl);
7475

7576
const optionSelect = (
7677
await cart.waitForOptionSelectors(firstLineItem)
7778
).first();
7879
const {optionName, nextValue} =
7980
await cart.selectDifferentOption(optionSelect);
8081

81-
await expect
82-
.poll(async () => {
83-
const href = await productLink.getAttribute('href');
84-
if (!href) {
85-
return false;
86-
}
87-
88-
const updatedProductUrl = new URL(href, page.url());
89-
return (
90-
href !== initialUrl &&
91-
updatedProductUrl.searchParams.get(optionName) === nextValue
92-
);
93-
})
94-
.toBe(true);
82+
const href = await productLink.getAttribute('href');
83+
assert(href);
84+
85+
const updatedProductUrl = new URL(href, page.url());
86+
expect(href).not.toBe(initialUrl);
87+
expect(updatedProductUrl.searchParams.get(optionName)).toBe(nextValue);
9588
});
9689

9790
test('maintains single line item when changing variants', async ({
@@ -117,12 +110,9 @@ test.describe('Custom Cart Method Recipe', () => {
117110
await cart.selectDifferentOption(optionSelect);
118111

119112
// Wait for the cart update to complete before checking preservation
120-
await expect
121-
.poll(async () => {
122-
const href = await productLink.getAttribute('href');
123-
return href !== null && href !== initialUrl;
124-
})
125-
.toBe(true);
113+
const href = await productLink.getAttribute('href');
114+
assert(href);
115+
expect(href).not.toBe(initialUrl);
126116

127117
await expect(cart.getLineItems()).toHaveCount(1);
128118
await expect(firstLineItem).toContainText('Quantity: 2');
@@ -147,12 +137,9 @@ test.describe('Custom Cart Method Recipe', () => {
147137
await cart.selectDifferentOption(optionSelect);
148138

149139
// Verify the cart update completed without navigating away
150-
await expect
151-
.poll(async () => {
152-
const href = await productLink.getAttribute('href');
153-
return href !== null && href !== initialProductUrl;
154-
})
155-
.toBe(true);
140+
const href = await productLink.getAttribute('href');
141+
assert(href);
142+
expect(href).not.toBe(initialProductUrl);
156143

157144
expect(page.url()).toBe(initialPageUrl);
158145
await expect(cartDialog).toBeVisible();

0 commit comments

Comments
 (0)