Use variable at threshold and check function

How can I use threshold_1 as the variable to define the options section?

const threshold_1 = "abc"
export const options: Partial<k6Options.Options> = {
	scenarios: xxx,
	thresholds: {
		// how can i define the threshold name as variable?
		threshold_1: ["p(95)<5000"],

Besides, how can I change “status OK” and"content OK" as the variable when I use the check function?

	const chk = check(res, {
		"status OK": (r) => item_res_status === 200,
		"content OK": (r) => item_res_body && item_res_body.indexOf("data\":{\"refId") !== -1,

Not sure about TypeScript, but you want to use a variable as the object key in JavaScript, you have to surround it with square brackets, like this:

export const options = {
	thresholds: {
		[ threshold_1 ]: ["p(95)<5000"],

More details: Object initializer - JavaScript | MDN

And, of course, you can always just gradually build up the object:

let checks = {};
checks[checkName1] = (r) => item_res_status === 200;
checks[checkName2] = someOtherFunction;
check(res, checks);
1 Like

yes, this is the perfect solution. Thx @ned