Skip to content

assert.throws() does not work correctly in node/vm spawned context #1604

@myocytebd

Description

@myocytebd

(chai 5.1.0 from npm, node 18.14.0, v8 10.2.154.23-node.22)
It seems that assert.throws() does not work correctly in vm spawned context.

const vm = require('node:vm');

const context = {};
vm.createContext(context);
setImmediate(runTest);

async function runTest() {
    context.chai = await import('chai');
    context.chai.assert.throws(() => { throw new Error('aaa.bbb'); }, /bbb/); // OK
    vm.runInContext(code, context); // Failure
}

const code = `
chai.assert.throws(() => { throw new Error('aaa.bbb'); }, /bbb/);
`;

Default context assert.throws() work as expected, but vm context assert.throws() asserts where it should pass.

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