hi all, i have a base fixture which configures some global bits like an authenticated user. in some cases i want to extend
that base fixture to test some edge cases, e.g. an unautheticated user. consider the following
import { test as base } from '@playwright/test'
type BaseFixture = {
user: { firstName: string; lastName: string }
}
const myFixture = base.extend<BaseFixture>({
user: {
firstName: 'Nick',
lastName: 'Williams',
},
})
i would then extend my fixture like so:
const myOtherFixture = myFixture.extend({
// Type '{ firstName: string; lastName: string; }' is not assignable to type 'undefined'
user: {
firstName: 'John',
lastName: 'Doe',
}
})
the problem is that i get a confusing typescript error as shown above. after some trial and error i notice that i can make this error go away by explicitly passing the generic type parameter to extend
:
const myOtherFixture = myFixture.extend<BaseFixture>({
user: {
firstName: 'John',
lastName: 'Doe',
}
})
am i doing something wrong to trigger the TS error? is this a bug in playwright? or is it expected that you always explicitly pass the type param (in which case, should it be made non-optional)?
This thread is trying to answer question "No information provided"
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].