[test] Added failing test for .save()
regression introduced by @russfrank in 36e061c4bd
This commit is contained in:
parent
04e22303bd
commit
7e8d9d6bce
2 changed files with 77 additions and 0 deletions
38
test/mocks/mock-store.js
Normal file
38
test/mocks/mock-store.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* mock-store.js: Mock store for ensuring certain operations are actually called.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var util = require('util'),
|
||||
events = require('events'),
|
||||
nconf = require('../../lib/nconf');
|
||||
|
||||
var Mock = nconf.Mock = function () {
|
||||
events.EventEmitter.call(this);
|
||||
this.type = 'mock';
|
||||
};
|
||||
|
||||
// Inherit from Memory store.
|
||||
util.inherits(Mock, events.EventEmitter);
|
||||
|
||||
//
|
||||
// ### function save (value, callback)
|
||||
// #### @value {Object} _Ignored_ Left here for consistency
|
||||
// #### @callback {function} Continuation to respond to when complete.
|
||||
// Waits `1000ms` and then calls the callback and emits the `save` event.
|
||||
//
|
||||
Mock.prototype.save = function (value, callback) {
|
||||
if (!callback && typeof value === 'function') {
|
||||
callback = value;
|
||||
value = null;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
setTimeout(function () {
|
||||
self.emit('save');
|
||||
callback();
|
||||
}, 1000);
|
||||
};
|
39
test/provider-save-test.js
Normal file
39
test/provider-save-test.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* provider-save-test.js: Ensures consistency for Provider `save` operations.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
vows = require('vows'),
|
||||
nconf = require('../lib/nconf');
|
||||
|
||||
//
|
||||
// Expose `nconf.Mock`
|
||||
//
|
||||
require('./mocks/mock-store');
|
||||
|
||||
vows.describe('nconf/provider').addBatch({
|
||||
"When using nconf": {
|
||||
"an instance of 'nconf.Provider'": {
|
||||
"with a Mock store": {
|
||||
topic: function () {
|
||||
return nconf.use('mock');
|
||||
},
|
||||
"the save() method": {
|
||||
topic: function () {
|
||||
var mock = nconf.stores.mock,
|
||||
that = this;
|
||||
|
||||
mock.on('save', function () { that.saved = true });
|
||||
nconf.save(this.callback);
|
||||
},
|
||||
"should actually save before responding": function () {
|
||||
assert.isTrue(this.saved);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
Loading…
Reference in a new issue