在 fixture.before 或 fixture.after 钩子中使用的函数中访问 ctx 对象

问题描述 投票:0回答:0

是否可以访问函数中的

ctx
对象,该函数将在 fixture.before 或 fixture.after 钩子中使用?

这是我自己试过的一段代码:

util.js

export function testCtxObject() {
    ctx.test = '123'
}

test.js

import { testCtxObject } from 'util';

fixture('Access ctx object in fixture hooks')
    .before(async (ctx) => {
        testCtxObject();
    });

...

当我在

test.js
中运行测试时,我最终得到这个错误:

1) - Error in fixture.before hook -
    Cannot implicitly resolve the test run in the context of which the test controller
    action should be executed. Use test function's 't' argument instead.
testcafe
© www.soinside.com 2019 - 2024. All rights reserved.