//test to check if the getStatesForRegions response body includes the duplicate states
test.only('should not include duplicate states in the /getStatesForRegions response body ',
async ({page}) => {
test.slow();
await page.route('**/getStatesForRegions', async (route) => {
// Fetch original response.
const response = await page.request.fetch(route.request());
// Add a prefix to the title.
let json = ['A', 'A'];//await response.json();
//check if the response body includes the duplicate states
expect(hasDuplicates(json)).toBeFalsy();//HERE
});
//select austria and belgium
await page.locator('#select-country').selectOption(['Austria', 'Belgium']);
await page.locator('.search').click();
});
hasDuplicates
//not the best but just meant for tests
function hasDuplicates(arr: string[]) {
const set = new Set(arr);
return set.size < arr.length;
}
Why is this test passing even if I switch the assertion to .toBeTruthy()?
This thread is trying to answer question "Why is this test passing even if I switch the assertion to .toBeTruthy()?"
test('route', async ({page, }) => {
await page.route('**/index', async (route) => {
await route.fulfill({ body: '<a href="/search">search</a>' });
});
const searchPromise = new Promise<[string, string]>(async resolve => {
await page.route('**/search', async (route) => {
await route.fulfill({ body: '<h1>no results</h1>' });
resolve(['A', 'B']);
});
});
await page.goto('http://localhost:8080/index');
await page.locator('a').click();
const [first, second] = await searchPromise;
expect(first === second).toBeFalsy();
});
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].