Skip to content

[Feature]: Represent ToHaveJSPropertyAsync for JS value undefined #3299

@rajsite

Description

@rajsite

🚀 Feature Request

Would like to be able to assert that an element has a property with JS value undefined using ToHaveJSPropertyAsync. It's not clear from documentation or tests in playwright-dotnet how that is done:

[PlaywrightTest("playwright-test/playwright.expect.misc.spec.ts", "should support toHaveJSProperty")]
public async Task ShouldSupportToHaveJSProperty()
{
await Page.SetContentAsync("<div></div>");
await Page.EvalOnSelectorAsync("div", "e => e.foo = { a: 1, b: 'string', c: new Date(1627503992000) }");
var locator = Page.Locator("div");
await Expect(locator).ToHaveJSPropertyAsync("foo", new Dictionary<string, object>
{
["a"] = 1,
["b"] = "string",
["c"] = DateTime.Parse("2021-07-28T20:26:32.000Z", CultureInfo.InvariantCulture),
});
await Page.EvalOnSelectorAsync("div", "e => e.foo = false");
await Expect(locator).ToHaveJSPropertyAsync("foo", false);
await Expect(locator).Not.ToHaveJSPropertyAsync("foo", true);
await Page.EvalOnSelectorAsync("div", "e => e.itsNull = null");
await Expect(locator).ToHaveJSPropertyAsync("itsNull", null);
}

Seems to be possible in the JS library based on tests:
https://github.com/microsoft/playwright/blob/dcd350445226ec3c54cc16e8cad1189c61bf07c8/tests/page/expect-misc.spec.ts#L193-L197

Example

No response

Motivation

Better align playwright-dotnet with capabilities of playwright JS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions