fix(inspector): render expect.not correctly (#19125)

Also fixes the same in expect logs.

References #19083.
This commit is contained in:
Dmitry Gozman 2022-11-28 20:50:16 -08:00 committed by GitHub
parent dd18792087
commit 4f72a895e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 9 deletions

View File

@ -36,7 +36,7 @@ export async function toBeTruthy(
const timeout = currentExpectTimeout(options);
const { matches, log, timedOut } = await query(this.isNot, timeout, captureStackTrace('expect.' + matcherName));
const { matches, log, timedOut } = await query(this.isNot, timeout, captureStackTrace(`expect.${this.isNot ? 'not.' : ''}${matcherName}`));
const message = () => {
return matcherHint(this, matcherName, undefined, '', matcherOptions, timedOut ? timeout : undefined) + callLogText(log);

View File

@ -327,7 +327,7 @@ export async function toHaveScreenshot(
maxDiffPixelRatio: undefined,
};
const customStackTrace = captureStackTrace(`expect.toHaveScreenshot`);
const customStackTrace = captureStackTrace(`expect.${this.isNot ? 'not.' : ''}toHaveScreenshot`);
const hasSnapshot = fs.existsSync(helper.snapshotPath);
if (this.isNot) {
if (!hasSnapshot)

View File

@ -59,7 +59,7 @@ export async function toMatchText(
const timeout = currentExpectTimeout(options);
const { matches: pass, received, log, timedOut } = await query(this.isNot, timeout, captureStackTrace('expect.' + matcherName));
const { matches: pass, received, log, timedOut } = await query(this.isNot, timeout, captureStackTrace(`expect.${this.isNot ? 'not.' : ''}${matcherName}`));
const stringSubstring = options.matchSubstring ? 'substring' : 'string';
const receivedString = received || '';
const message = pass

View File

@ -44,7 +44,7 @@ export const CallLogView: React.FC<CallLogProps> = ({
const locatorCall = `page.${locator}`;
let titlePrefix = callLog.title;
let titleSuffix = '';
if (callLog.title.startsWith('expect.to')) {
if (callLog.title.startsWith('expect.to') || callLog.title.startsWith('expect.not.to')) {
titlePrefix = 'expect(';
titleSuffix = `).${callLog.title.substring('expect.'.length)}()`;
} else if (callLog.title.startsWith('locator.')) {

View File

@ -230,6 +230,7 @@ it.describe('pause', () => {
const scriptPromise = (async () => {
await page.pause();
await expect(page.locator('button')).toHaveText('Submit');
await expect(page.locator('button')).not.toHaveText('Submit2');
await page.pause(); // 2
})();
const recorderPage = await recorderPageGetter();
@ -238,6 +239,7 @@ it.describe('pause', () => {
expect(await sanitizeLog(recorderPage)).toEqual([
'page.pause- XXms',
'expect(page.locator(\'button\')).toHaveText()- XXms',
'expect(page.locator(\'button\')).not.toHaveText()- XXms',
'page.pause',
]);
await recorderPage.click('[title="Resume (F8)"]');

View File

@ -58,7 +58,7 @@ test.describe('toBeChecked', () => {
await page.setContent('<input type=checkbox checked></input>');
const locator = page.locator('input');
const error = await expect(locator).not.toBeChecked({ timeout: 1000 }).catch(e => e);
expect(error.message).toContain(`expect.toBeChecked with timeout 1000ms`);
expect(error.message).toContain(`expect.not.toBeChecked with timeout 1000ms`);
expect(error.message).toContain(`locator resolved to <input checked type="checkbox"/>`);
});
@ -73,7 +73,7 @@ test.describe('toBeChecked', () => {
await page.setContent('<div>no inputs here</div>');
const locator2 = page.locator('input2');
const error = await expect(locator2).not.toBeChecked({ timeout: 1000 }).catch(e => e);
expect(error.message).toContain(`expect.toBeChecked with timeout 1000ms`);
expect(error.message).toContain(`expect.not.toBeChecked with timeout 1000ms`);
expect(error.message).toContain('waiting for locator(\'input2\')');
});
@ -368,7 +368,7 @@ test.describe('toBeHidden', () => {
await page.setContent('<div></div>');
const locator = page.locator('button');
const error = await expect(locator).not.toBeHidden({ timeout: 1000 }).catch(e => e);
expect(error.message).toContain(`expect.toBeHidden with timeout 1000ms`);
expect(error.message).toContain(`expect.not.toBeHidden with timeout 1000ms`);
});
test('with impossible timeout .not', async ({ page }) => {

View File

@ -255,11 +255,11 @@ test.describe('toHaveAttribute', () => {
await expect(locator).toHaveAttribute('checked', /.*/);
{
const error = await expect(locator).not.toHaveAttribute('checked', '', { timeout: 1000 }).catch(e => e);
expect(error.message).toContain('expect.toHaveAttribute with timeout 1000ms');
expect(error.message).toContain('expect.not.toHaveAttribute with timeout 1000ms');
}
{
const error = await expect(locator).not.toHaveAttribute('checked', /.*/, { timeout: 1000 }).catch(e => e);
expect(error.message).toContain('expect.toHaveAttribute with timeout 1000ms');
expect(error.message).toContain('expect.not.toHaveAttribute with timeout 1000ms');
}
});
});