Check the Unexpected Value error message in the console
Expected behavior
Expected behaviour: Any type should be serialized when HooksConfig value is passed to mount(), however innerSerializeValue() doesn't serialize function type field.
store.ts
export type User = {
name: string;
age: number;
toUserString: () => string; // <== function type
};
export const useStore = defineStore('store', () => {
const user = ref<User>({ name: 'Steve', age: 20, toUserString: () => '' });
return {
user,
};
});
import { test, expect } from '@playwright/experimental-ct-vue';
import { type HooksConfig } from 'playwright';
import { type User } from '@/stores/store';
import TestPage from './TestPage.vue';
test.describe('<TestPage />', () => {
test('Test User', async ({ mount }) => {
const mockTestUser: User = {
name: 'Jackson',
age: 30,
toUserString: () => {
return 'Hello';
},
};
const component = await mount<HooksConfig>(TestPage, {
hooksConfig: { store: { user: mockTestUser } },
});
const name = component.getByTestId('name');
await expect(name).toHaveText('Jackson');
});
});
Actual behavior
Throw error message Unexpected value'
Additional context
I've debugged this issue and found out the part that caused the issue.
There is a innerSerializeValue() that serializes arguments that is passed via mount() in
...PATH/node_modules/.pnpm/@playwright+experimental-ct-core@1.47.0_@types+node@20.16.5/node_modules/playwright-core/lib/protocol/serializers.js
There is no code to handle function in the conditions.
function innerSerializeValue(value, handleSerializer, visitorInfo) {
const handle = handleSerializer(value);
if ('fallThrough' in handle) value = handle.fallThrough;else return handle;
if (typeof value === 'symbol') return {
v: 'undefined'
};
if (Object.is(value, undefined)) return {
v: 'undefined'
};
if (Object.is(value, null)) return {
v: 'null'
};
if (Object.is(value, NaN)) return {
v: 'NaN'
};
if (Object.is(value, Infinity)) return {
v: 'Infinity'
};
if (Object.is(value, -Infinity)) return {
v: '-Infinity'
};
if (Object.is(value, -0)) return {
v: '-0'
};
if (typeof value === 'boolean') return {
b: value
};
if (typeof value === 'number') return {
n: value
};
if (typeof value === 'string') return {
s: value
};
if (typeof value === 'bigint') return {
bi: value.toString()
};
if (isError(value)) return {
e: {
n: value.name,
m: value.message,
s: value.stack || ''
}
};
if (isDate(value)) return {
d: value.toJSON()
};
if (isURL(value)) return {
u: value.toJSON()
};
if (isRegExp(value)) return {
r: {
p: value.source,
f: value.flags
}
};
const id = visitorInfo.visited.get(value);
if (id) return {
ref: id
};
if (Array.isArray(value)) {
const a = [];
const id = ++visitorInfo.lastId;
visitorInfo.visited.set(value, id);
for (let i = 0; i < value.length; ++i) a.push(innerSerializeValue(value[i], handleSerializer, visitorInfo));
return {
a,
id
};
}
if (typeof value === 'object') {
const o = [];
const id = ++visitorInfo.lastId;
visitorInfo.visited.set(value, id);
for (const name of Object.keys(value)) o.push({
k: name,
v: innerSerializeValue(value[name], handleSerializer, visitorInfo)
});
return {
o,
id
};
}
throw new Error('Unexpected value');
}
Version
1.47.0
Steps to reproduce
pnpm i
andpnpm test-ct
Unexpected Value
error message in the consoleExpected behavior
Expected behaviour: Any type should be serialized when
HooksConfig
value is passed tomount()
, howeverinnerSerializeValue()
doesn't serializefunction type
field.store.ts
index.ts
TestPage.ct.ts
Actual behavior
Throw error message
Unexpected value'
Additional context
I've debugged this issue and found out the part that caused the issue.
There is a
innerSerializeValue()
that serializes arguments that is passed viamount()
in...PATH/node_modules/.pnpm/@playwright+experimental-ct-core@1.47.0_@types+node@20.16.5/node_modules/playwright-core/lib/protocol/serializers.js
There is no code to handle
function
in the conditions.Environment