How can I access global context in tests?

I'm using node-red-node-test-helper for tests of my nodes. During work nodes change global context and I should text this changes. Here is my code:

let n1 = helper.getNode("n1");
n1.on('input', function(msg){
    let gcontext = n1.context().global;
    // other stuff
}

But gcontext is undefined. Am I missing something?

There is documentation how to access data in context. You have the wrong syntax

Hi @Roman

The test helper doesn't automatically initialise context. It probably should do more to help in that area.

For now, you have to initialise context yourself - you can see how that is done in the Change node's unit tests - node-red/15-change_spec.js at master · node-red/node-red · GitHub

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.