Skip to content

Commit

Permalink
* added test cases for all methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fresc81 committed Apr 17, 2016
1 parent ac93f68 commit c487a20
Showing 1 changed file with 138 additions and 28 deletions.
166 changes: 138 additions & 28 deletions test/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

// this should reveal wrong iteration used for arrays
// this should reveal wrong iteration on arrays
Array.prototype.someNewMethod = function() {};

var test = require('unit.js');

describe('winreg', function(){

it('we\'re running on Windows', function () {
it('running on Windows', function () {

test.string(process.platform)
. is('win32');
Expand All @@ -23,7 +23,7 @@ describe('winreg', function(){

});

// create a uniqe registry key in HKCU to test in...
// create a uniqe registry key in HKCU to test in
var regKey = new Registry({
hive: Registry.HKCU,
key: '\\Software\\AAA_' + new Date().toISOString()
Expand All @@ -36,11 +36,24 @@ describe('winreg', function(){

});

// a key that has subkeys in it
var softwareKey = new Registry({
hive: Registry.HKCU,
key: '\\Software'
});

it('softwareKey is instance of Registry', function(){

test.object(softwareKey)
. isInstanceOf(Registry);

});

describe('Registry', function (){

describe('keyExists()', function(){

it('regKey has method', function () {
it('regKey has keyExists method', function () {

test.object(regKey)
. hasProperty('keyExists');
Expand Down Expand Up @@ -69,7 +82,7 @@ describe('winreg', function(){

describe('create()', function(){

it('regKey has method', function () {
it('regKey has create method', function () {

test.object(regKey)
. hasProperty('create');
Expand Down Expand Up @@ -108,23 +121,35 @@ describe('winreg', function(){

}); // end - describe create()

describe('keys()', function (){
describe('set()', function (){

it('regKey has method', function () {
it('regKey has set method', function () {

test.object(regKey)
. hasProperty('keys');
. hasProperty('set');

test.function(regKey.keys)
. hasName('keys');
test.function(regKey.set)
. hasName('set');

});

}); // end - describe keys()
it('can set a string value', function (done) {

regKey.set('SomeString', Registry.REG_SZ, 'SomeValue', function (err) {

if (err) throw err;

done();

});

});

}); // end - describe set

describe('valueExists()', function (){

it('regKey has method', function () {
it('regKey has valueExists method', function () {

test.object(regKey)
. hasProperty('valueExists');
Expand All @@ -134,11 +159,26 @@ describe('winreg', function(){

});

it('can check for existing string value', function (done) {

regKey.valueExists('SomeString', function (err, exists) {

if (err) throw err;

test.bool(exists)
. isTrue();

done();

});

});

}); // end - describe valueExists

describe('get()', function (){

it('regKey has method', function () {
it('regKey has get method', function () {

test.object(regKey)
. hasProperty('get');
Expand All @@ -148,11 +188,26 @@ describe('winreg', function(){

});

it('can get a string value', function (done) {

regKey.get('SomeString', function (err, item) {

if (err) throw err;

test.object(item)
. hasProperty('value', 'SomeValue');

done();

});

});

}); // end - describe get

describe('values()', function (){

it('regKey has method', function () {
it('regKey has values method', function () {

test.object(regKey)
. hasProperty('values');
Expand All @@ -162,25 +217,31 @@ describe('winreg', function(){

});

}); // end - describe values

describe('set()', function (){

it('regKey has method', function () {

test.object(regKey)
. hasProperty('set');
it('returns array of RegistryItem objects', function (done) {

test.function(regKey.set)
. hasName('set');
regKey.values(function (err, items) {

if (err) throw err;

for (var i=0; i<items.length; i++) {

var item = items[i];

test.object(item)
. hasProperty('value');

}
done();

});

});

}); // end - describe set
}); // end - describe values

describe('remove()', function (){

it('regKey has method', function () {
it('regKey has remove method', function () {

test.object(regKey)
. hasProperty('remove');
Expand All @@ -190,11 +251,60 @@ describe('winreg', function(){

});

it('can remove a string value', function (done) {

regKey.remove('SomeString', function (err) {

if (err) throw err;

done();

});

});

}); // end - describe remove

describe('keys()', function (){

it('regKey has keys method', function () {

test.object(regKey)
. hasProperty('keys');

test.function(regKey.keys)
. hasName('keys');

});

it('returns array of Registry objects', function (done) {

softwareKey.keys(function (err, keys) {

if (err) throw err;

test.array(keys);

for (var i=0; i<keys.length; i++) {

var key = keys[i];

test.object(key)
. isInstanceOf(Registry);

}

done();

});

});

}); // end - describe keys()

describe('clear()', function (){

it('regKey has method', function () {
it('regKey has clear method', function () {

test.object(regKey)
. hasProperty('clear');
Expand All @@ -208,7 +318,7 @@ describe('winreg', function(){

describe('destroy()', function(){

it('regKey has method', function () {
it('regKey has destroy method', function () {

test.object(regKey)
. hasProperty('destroy');
Expand Down

0 comments on commit c487a20

Please sign in to comment.