Skip to content

Commit

Permalink
adding another test for function defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Deverell committed Apr 27, 2016
1 parent 3e0856b commit a9792b8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ helpers.schema = {
message: 'riffwabbles can only be letters, numbers, and dashes',
default: 'foobizzles'
},
functiondefaultpluralanimal: {
message: 'function default plural animal',
default: function () {
return prompt.history('animal').value + 's';
}
},
functiondefaulttest: {
message: 'function default test',
default: function () {
Expand Down
36 changes: 36 additions & 0 deletions test/prompt-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,42 @@ vows.describe('prompt').addBatch({
}
}
}
}).addBatch({
"When using prompt": {
"the get() method": {
"with a simple string prompt": {
"that is a property name in prompt.properties": {
"with a function default returning a string literal": {
topic: function () {
var that = this;

helpers.stdout.once('data', function (msg) {
// we really need the second message, so we'll
// ignore the first and look out for the second
helpers.stdout.once('data', function (msg) {
that.msg = msg;
})
});

prompt.properties.animal = schema.properties.animal;
prompt.properties.functiondefaultpluralanimal =
schema.properties.functiondefaultpluralanimal;
prompt.get(['animal', 'functiondefaultpluralanimal'], this.callback);
helpers.stdin.writeSequence(['cat\n', '\n']);
},
"should respond with the default value function's return value": function (err, result) {
assert.isNull(err);
assert.notStrictEqual(this.msg.indexOf('function default plural animal'), -1);
assert.notStrictEqual(this.msg.indexOf('(cats)'), -1);
assert.strictEqual(result['animal'], 'cat');
assert.include(result, 'functiondefaultpluralanimal');
assert.strictEqual(result['functiondefaultpluralanimal'], 'cats');
}
},
}
}
}
}
}).addBatch({
"When using prompt": {
"the get() method": {
Expand Down

0 comments on commit a9792b8

Please sign in to comment.