mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
allow $parent access of flow context
This commit is contained in:
@@ -225,6 +225,50 @@ describe('context', function() {
|
||||
});
|
||||
})
|
||||
|
||||
describe("$parent", function() {
|
||||
it('should access $parent', function() {
|
||||
var context0 = Context.get("0","flowA");
|
||||
var context1 = Context.get("1","flowB", context0);
|
||||
var parent = context1.get("$parent");
|
||||
parent.should.equal(context0);
|
||||
});
|
||||
|
||||
it('should get undefined for $parent of root', function() {
|
||||
var context0 = Context.get("0","flowA");
|
||||
var context1 = Context.get("1","flowB", context0);
|
||||
var parent = context1.get("$parent.$parent");
|
||||
should.equal(parent, undefined);
|
||||
});
|
||||
|
||||
it('should get $parent', function() {
|
||||
var context0 = Context.get("0","flowA");
|
||||
var context1 = Context.get("1","flowB", context0);
|
||||
var parent = context1.get("$parent");
|
||||
context0.set("K", "v");
|
||||
var v = context1.get("$parent.K");
|
||||
should.equal(v, "v");
|
||||
});
|
||||
|
||||
it('should set $parent', function() {
|
||||
var context0 = Context.get("0","flowA");
|
||||
var context1 = Context.get("1","flowB", context0);
|
||||
var parent = context1.get("$parent");
|
||||
context1.set("$parent.K", "v");
|
||||
var v = context0.get("K");
|
||||
should.equal(v, "v");
|
||||
});
|
||||
|
||||
it('should not contain $parent in keys', function() {
|
||||
var context0 = Context.get("0","flowA");
|
||||
var context1 = Context.get("1","flowB", context0);
|
||||
var parent = context1.get("$parent");
|
||||
context0.set("K0", "v0");
|
||||
context1.set("K1", "v1");
|
||||
var keys = context1.keys();
|
||||
keys.should.have.length(1);
|
||||
keys[0].should.equal("K1");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user