-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Make sure Placeholders are recursively resolved + add tests
- Loading branch information
Showing
3 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
let assert = require('assert'), | ||
Blast, | ||
Trail, | ||
Placeholder; | ||
|
||
describe('Placeholder', function() { | ||
Blast = require('../index.js')(); | ||
Trail = Blast.Classes.Develry.Trail; | ||
Placeholder = Blast.Classes.Develry.Placeholder; | ||
|
||
describe('.deepResolve(input, ...args)', () => { | ||
it('should recursively resolve all placeholders in objects', () => { | ||
|
||
let pledge = new Pledge(), | ||
trail = Trail.fromArrow('my->nested->path'); | ||
|
||
pledge.resolve('PLEDGED!'); | ||
|
||
let context = { | ||
my: { | ||
nested: { | ||
path: 1, | ||
} | ||
} | ||
}; | ||
|
||
let data = { | ||
pledge: pledge, | ||
trail : trail, | ||
deep : { | ||
arr: [pledge, trail] | ||
} | ||
}; | ||
|
||
let resolved = Placeholder.deepResolve(data, context); | ||
|
||
assert.deepStrictEqual(resolved, { | ||
pledge: 'PLEDGED!', | ||
trail : 1, | ||
deep : { | ||
arr : ['PLEDGED!', 1] | ||
} | ||
}); | ||
}); | ||
|
||
it('should also resolve values in resolved values', () => { | ||
|
||
let pledge = new Pledge(), | ||
trail = Trail.fromArrow('my->nested->path'); | ||
|
||
pledge.resolve('PLEDGED!'); | ||
|
||
let somewhere_else = new Pledge(); | ||
somewhere_else.resolve('ELSE!'); | ||
|
||
let context = { | ||
my: { | ||
nested: { | ||
path: Trail.fromArrow('somewhere->else'), | ||
} | ||
}, | ||
somewhere: { | ||
else: somewhere_else, | ||
} | ||
}; | ||
|
||
let data = { | ||
pledge: pledge, | ||
trail : trail, | ||
deep : { | ||
arr: [pledge, trail] | ||
} | ||
}; | ||
|
||
let resolved = Placeholder.deepResolve(data, context); | ||
|
||
assert.deepStrictEqual(resolved, { | ||
pledge: 'PLEDGED!', | ||
trail : 'ELSE!', | ||
deep : { | ||
arr : ['PLEDGED!', 'ELSE!'] | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
let assert = require('assert'), | ||
Blast, | ||
Trail; | ||
|
||
describe('Trail', function() { | ||
Blast = require('../index.js')(); | ||
Trail = Blast.Classes.Develry.Trail; | ||
|
||
describe('.fromDot(path)', () => { | ||
it('should create a new trail', () => { | ||
let trail = Trail.fromDot('this.is.a.path'); | ||
}); | ||
}); | ||
|
||
describe('#getResolvedValue(context)', () => { | ||
it('should extract the path from the given context', () => { | ||
|
||
let trail = Trail.fromDot('my.nested.path'); | ||
let obj = { | ||
my: { | ||
nested: { | ||
path: 1, | ||
} | ||
} | ||
}; | ||
|
||
let value = trail.getResolvedValue(obj); | ||
|
||
assert.strictEqual(value, 1); | ||
}); | ||
}); | ||
|
||
}); |