From 4166598bb6928db81b6546b1acaedf616fb85cc1 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 4 Feb 2014 01:57:33 -0200 Subject: [PATCH] JSCS: checking test/test-node.js --- Gruntfile.js | 2 +- test/test-node.js | 81 +++++++++++++++++++++++------------------------ 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 01b0fb0..2801a22 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -62,7 +62,7 @@ module.exports = function( grunt ) { options: { jshintrc: '.jshintrc' }, - all: [ 'Gruntfile.js', 'src/**/*.js', 'test/unit/*.js' ] + all: [ 'Gruntfile.js', 'src/**/*.js', 'test/**/*.js' ] }, jscs: { src: '<%= jshint.all %>', diff --git a/test/test-node.js b/test/test-node.js index 413209f..8d81f59 100644 --- a/test/test-node.js +++ b/test/test-node.js @@ -1,16 +1,15 @@ 'use strict'; var Dexter = require( '../src/Dexter' ); -var Dexter_fakeXHR = require( '../src/Dexter.fakeXHR' ); exports.Environment = { - 'Dexter is Here!' : function ( test ) { + 'Dexter is Here!': function( test ) { test.expect( 2 ); test.equal( typeof( Dexter ), 'object', 'Dexter is an object'); test.ok( Dexter, 'Dexter is not falsy' ); test.done(); }, - 'Dexter functions' : function ( test ) { + 'Dexter functions': function( test ) { test.expect( 3 ); test.equal( typeof( Dexter.spy ), 'function', 'Dexter.spy is a function' ); test.equal( typeof( Dexter.fake ), 'function', 'Dexter.fake is a function' ); @@ -20,9 +19,9 @@ exports.Environment = { }; exports.Fake = { - setUp : function ( callback ) { + setUp: function( callback ) { this.foo = {}; - this.foo.bar = function ( test ) { + this.foo.bar = function( test ) { test.expect( 1 ); test.ok( false, 'fake shoud not call original method' ); test.done(); @@ -30,13 +29,13 @@ exports.Fake = { this.fake = Dexter.fake( this.foo, 'bar' ); callback(); }, - 'returned object' : function ( test ) { + 'returned object': function( test ) { test.expect( 2 ); test.equal( typeof this.fake, 'object', 'Dexter.fake returns and object' ); test.ok( this.fake.isActive, 'fake.isActive === true' ); test.done(); }, - 'call count' : function ( test ) { + 'call count': function( test ) { var i; test.expect( 11 ); for ( i = 0 ; i < 11 ; ++i ) { @@ -45,8 +44,8 @@ exports.Fake = { } test.done(); }, - 'restore()' : function ( test ) { - this.foo.otherBar = function () { + 'restore()': function( test ) { + this.foo.otherBar = function() { test.ok( true, 'fake restore objects' ); }; @@ -58,8 +57,8 @@ exports.Fake = { test.deepEqual( fake.isActive, false, 'fake.isActive === false after restoring' ); test.done(); }, - 'callback' : function ( test ) { - this.fake.callback = function ( a, b, c ) { + 'callback': function( test ) { + this.fake.callback = function( a, b, c ) { test.ok( true, '.callback is set' ); test.deepEqual( [ a, b, c ], [ 1, 2, 3 ], 'callback arguments working' ); }; @@ -68,7 +67,7 @@ exports.Fake = { this.fake.restore(); - this.fake = Dexter.fake( this.foo, 'bar', function () { + this.fake = Dexter.fake( this.foo, 'bar', function() { test.ok( true, 'callback can be set at fake creation' ); return 17; }); @@ -79,10 +78,10 @@ exports.Fake = { }; exports.Restore = { - setUp : function ( callback ) { - this.myMock1 = function () {}; - this.myMock2 = function () {}; - this.myMock3 = function () {}; + setUp: function( callback ) { + this.myMock1 = function() {}; + this.myMock2 = function() {}; + this.myMock3 = function() {}; this.fakes = []; this.fakes.push( Dexter.fake( this, 'myMock1' ) ); @@ -90,13 +89,13 @@ exports.Restore = { this.fakes.push( Dexter.spy( this, 'myMock3' ) ); callback(); }, - tearDown : function ( callback ) { - while( this.fakes.length ) { + tearDown: function( callback ) { + while ( this.fakes.length ) { this.fakes.pop().restore(); } callback(); }, - 'storing methods' : function ( test ) { + 'storing methods': function( test ) { var fakes = this.fakes, stored = Dexter.stored, item; @@ -109,21 +108,21 @@ exports.Restore = { } test.done(); }, - 'restoring' : function ( test ) { + 'restoring': function( test ) { test.expect( 3 ); test.ok( Dexter.stored.length >= 3, 'Dexter.stored has items' ); test.ok( Dexter.restore(), 'Dexter.restore() => true' ); test.strictEqual( Dexter.stored.length, 0, 'Dexter.stored empty after Dexter.restore()' ); test.done(); }, - 'restoring for sure' : function ( test ) { + 'restoring for sure': function( test ) { test.expect( 1 ); - this.myFn = function () { + this.myFn = function() { test.ok( true, 'restored function working' ); test.done(); }; - Dexter.fake( this, 'myFn', function () { + Dexter.fake( this, 'myFn', function() { throw 'do not call me'; }); @@ -135,34 +134,34 @@ exports.Restore = { }; exports.Spy = { - setUp: function ( callback ) { + setUp: function( callback ) { this.foo = {}; - this.foo.bar = function ( test ) { + this.foo.bar = function( test ) { test.ok( true, 'spy preserve method calling' ); return 'foo!'; }; this.spy = Dexter.spy( this.foo, 'bar' ); callback(); }, - 'returned object' : function ( test ) { + 'returned object': function( test ) { test.expect( 5 ); test.equal( typeof( this.spy ), 'object', 'Dexter.spy returns and object' ); test.ok( this.spy.isActive, 'spy.isActive === true' ); - test.throws( function () { + test.throws( function() { Dexter.spy( this.foo, 'whateverDoesntExist' ); }, 'raises an error if method doesnt exist' ); - test.throws( function () { + test.throws( function() { Dexter.spy(); }, 'raises an error without arguments' ); - test.throws( function () { - Dexter.spy( this.foo, function () {} ); + test.throws( function() { + Dexter.spy( this.foo, function() {} ); }, 'raises an error if method name isn\'t a string' ); test.done(); }, - 'restore()' : function ( test ) { + 'restore()': function( test ) { test.expect( 3 ); this.spy.restore(); @@ -173,7 +172,7 @@ exports.Spy = { test.deepEqual( this.spy.isActive, false, 'spy.isActive === false after restoring' ); test.done(); }, - 'call count' : function ( test ) { + 'call count': function( test ) { test.expect( 22 ); var i; for ( i = 0 ; i < 11 ; ++i ) { @@ -182,9 +181,9 @@ exports.Spy = { } test.done(); }, - 'arguments' : function ( test ) { + 'arguments': function( test ) { test.expect( 1 ); - this.foo.otherBar = function ( a, b, c ) { + this.foo.otherBar = function( a, b, c ) { test.deepEqual( [ a, b, c ], [ 'Dexter', 'is', 'here!' ], 'keeping arguments in the spied call' ); }; @@ -193,9 +192,9 @@ exports.Spy = { this.foo.otherBar( 'Dexter', 'is', 'here!' ); test.done(); }, - 'callback()' : function ( test ) { + 'callback()': function( test ) { test.expect( 6 ); - this.spy.callback = function ( t, a, b, c ) { + this.spy.callback = function( t, a, b, c ) { test.ok( true, '.callback is set' ); test.deepEqual( [ t, a, b, c ], [ test, 1, 2, 3 ], 'callback arguments working' ); }; @@ -204,7 +203,7 @@ exports.Spy = { this.spy.restore(); - this.spy = Dexter.spy( this.foo, 'bar', function () { + this.spy = Dexter.spy( this.foo, 'bar', function() { test.ok( true, 'callback can be set at spy creation' ); return 'bar!'; }); @@ -212,15 +211,15 @@ exports.Spy = { test.strictEqual( this.foo.bar(test), 'foo!', 'spy preserves returned value' ); test.done(); }, - 'callback() order' : function ( test ) { + 'callback() order': function( test ) { test.expect( 1 ); var foo = ''; - Dexter.__bar__ = function () { + Dexter.__bar__ = function() { foo = 'a'; }; - Dexter.spy( Dexter, '__bar__', function () { + Dexter.spy( Dexter, '__bar__', function() { foo += 'b'; }); @@ -229,4 +228,4 @@ exports.Spy = { test.strictEqual( foo, 'ab', 'callback called after spied function' ); test.done(); } -}; \ No newline at end of file +};