From 3474660894dd0e172a50de7918471fa5d2030b32 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 20 May 2014 22:25:55 -0300 Subject: [PATCH] Tests: Node tests now reuse QUnit tests, replacing nodeunit Fixes #18 --- Gruntfile.js | 15 ++- dist/dexter.js | 2 +- dist/dexter.min.js | 2 +- package.json | 6 +- test/test-node.js | 234 --------------------------------------- test/unit/environment.js | 34 +++--- test/unit/fake.js | 107 ++++++++++-------- test/unit/restore.js | 103 +++++++++-------- test/unit/spy.js | 167 +++++++++++++++------------- 9 files changed, 244 insertions(+), 426 deletions(-) delete mode 100644 test/test-node.js diff --git a/Gruntfile.js b/Gruntfile.js index ac332f6..9391dd5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -47,6 +47,14 @@ module.exports = function( grunt ) { }, all: [ 'test/*.html' ] }, + qunitnode: { + all: [ + 'test/unit/environment.js', + 'test/unit/spy.js', + 'test/unit/fake.js', + 'test/unit/restore.js' + ] + }, coveralls: { options: { force: true @@ -56,9 +64,6 @@ module.exports = function( grunt ) { src: 'build/report/lcov/lcov.info' } }, - nodeunit: { - all: [ 'test/test-node.js' ] - }, jshint: { options: { jshintrc: '.jshintrc' @@ -102,11 +107,11 @@ module.exports = function( grunt ) { [ 'grunt-contrib-concat', 'grunt-contrib-jshint', - 'grunt-contrib-nodeunit', 'grunt-contrib-uglify', 'grunt-contrib-watch', 'grunt-coveralls', 'grunt-jscs-checker', + 'grunt-qunitnode', 'grunt-qunit-istanbul' ].forEach( function( task ) { grunt.loadNpmTasks( task ); @@ -125,6 +130,6 @@ module.exports = function( grunt ) { }); // Default task. - grunt.registerTask( 'default', 'jshint jscs qunit concat uglify nodeunit'.split( ' ' ) ); + grunt.registerTask( 'default', 'jshint jscs qunit qunitnode concat uglify'.split( ' ' ) ); }; diff --git a/dist/dexter.js b/dist/dexter.js index 3804d39..70c0b55 100644 --- a/dist/dexter.js +++ b/dist/dexter.js @@ -1,4 +1,4 @@ -/*! DexterJS - v0.5.1 - 2014-05-20 +/*! DexterJS - v0.5.1 - 2014-06-01 * https://github.com/leobalter/DexterJS * Copyright (c) 2014 Leonardo Balter; Licensed MIT, GPL */ (function() { diff --git a/dist/dexter.min.js b/dist/dexter.min.js index 258fe45..9393e20 100644 --- a/dist/dexter.min.js +++ b/dist/dexter.min.js @@ -1,4 +1,4 @@ -/*! DexterJS - v0.5.1 - 2014-05-20 +/*! DexterJS - v0.5.1 - 2014-06-01 * https://github.com/leobalter/DexterJS * Copyright (c) 2014 Leonardo Balter; Licensed MIT, GPL */ diff --git a/package.json b/package.json index 967d81e..1c840e5 100644 --- a/package.json +++ b/package.json @@ -39,19 +39,19 @@ "bdd" ], "scripts": { - "ci": "grunt -v jshint jscs qunit nodeunit coveralls", - "test": "grunt -v jshint jscs qunit nodeunit" + "ci": "grunt -v jshint jscs qunit qunitnode coveralls", + "test": "grunt -v jshint jscs qunit qunitnode" }, "devDependencies": { "grunt": "0.4.2", "grunt-contrib-concat": "0.3.0", "grunt-contrib-jshint": "0.8.0", - "grunt-contrib-nodeunit": "0.3.2", "grunt-contrib-uglify": "0.3.2", "grunt-contrib-watch": "0.5.3", "grunt-coveralls": "0.3.0", "grunt-jscs-checker": "0.4.0", "grunt-qunit-istanbul": "0.3.0", + "grunt-qunitnode": "0.1.2", "mdoc": "0.3.4", "qunitjs": "1.14.0", "requirejs": "2.1.11" diff --git a/test/test-node.js b/test/test-node.js deleted file mode 100644 index 6c57b51..0000000 --- a/test/test-node.js +++ /dev/null @@ -1,234 +0,0 @@ -(function() { - 'use strict'; - - var Dexter = require( '../src/Dexter' ); - - exports.Environment = { - '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 ) { - 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' ); - test.equal( typeof( Dexter.fakeXHR ), 'undefined', 'Dexter.fakeXHR is a not function on Node environment' ); - test.done(); - } - }; - - exports.Fake = { - setUp: function( callback ) { - this.foo = {}; - this.foo.bar = function( test ) { - test.expect( 1 ); - test.ok( false, 'fake shoud not call original method' ); - test.done(); - }; - this.fake = Dexter.fake( this.foo, 'bar' ); - callback(); - }, - '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 ) { - var i; - test.expect( 11 ); - for ( i = 0 ; i < 11 ; ++i ) { - test.deepEqual( this.fake.called, i, 'fake.called === ' + i ); - this.foo.bar(); - } - test.done(); - }, - 'restore()': function( test ) { - this.foo.otherBar = function() { - test.ok( true, 'fake restore objects' ); - }; - - var fake = Dexter.fake( this.foo, 'otherBar' ); - fake.restore(); - this.foo.otherBar(); - - test.deepEqual( fake.called, 0, 'restored fake should not be affected by further calls' ); - test.deepEqual( fake.isActive, false, 'fake.isActive === false after restoring' ); - test.done(); - }, - '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' ); - }; - - this.foo.bar( 1, 2, 3 ); - - this.fake.restore(); - - this.fake = Dexter.fake( this.foo, 'bar', function() { - test.ok( true, 'callback can be set at fake creation' ); - return 17; - }); - - test.strictEqual( this.foo.bar(), 17, 'fake returned value set in callback' ); - test.done(); - } - }; - - exports.Restore = { - setUp: function( callback ) { - this.myMock1 = function() {}; - this.myMock2 = function() {}; - this.myMock3 = function() {}; - - this.fakes = []; - this.fakes.push( Dexter.fake( this, 'myMock1' ) ); - this.fakes.push( Dexter.fake( this, 'myMock2' ) ); - this.fakes.push( Dexter.spy( this, 'myMock3' ) ); - callback(); - }, - tearDown: function( callback ) { - while ( this.fakes.length ) { - this.fakes.pop().restore(); - } - callback(); - }, - 'storing methods': function( test ) { - var fakes = this.fakes, - stored = Dexter.stored, - item; - test.expect( 3 ); - while ( fakes.length ) { - item = fakes.pop(); - test.strictEqual( stored.pop(), item, 'Dexter stored item' ); - - item.restore(); - } - test.done(); - }, - '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 ) { - test.expect( 1 ); - this.myFn = function() { - test.ok( true, 'restored function working' ); - test.done(); - }; - - Dexter.fake( this, 'myFn', function() { - throw 'do not call me'; - }); - - Dexter.restore(); - - this.myFn(); - } - - }; - - exports.Spy = { - setUp: function( callback ) { - this.foo = {}; - 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 ) { - 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() { - Dexter.spy( this.foo, 'whateverDoesntExist' ); - }, 'raises an error if method doesnt exist' ); - - test.throws( function() { - Dexter.spy(); - }, 'raises an error without arguments' ); - - test.throws( function() { - Dexter.spy( this.foo, function() {} ); - }, 'raises an error if method name isn\'t a string' ); - test.done(); - }, - 'restore()': function( test ) { - test.expect( 3 ); - this.spy.restore(); - - // 1 ok - this.foo.bar(test); - - test.deepEqual( this.spy.called, 0, 'restored spy should not be affected by further calls' ); - test.deepEqual( this.spy.isActive, false, 'spy.isActive === false after restoring' ); - test.done(); - }, - 'call count': function( test ) { - test.expect( 22 ); - var i; - for ( i = 0 ; i < 11 ; ++i ) { - test.deepEqual( this.spy.called, i, 'spy.called === ' + i ); - this.foo.bar(test); - } - test.done(); - }, - 'arguments': function( test ) { - test.expect( 1 ); - this.foo.otherBar = function( a, b, c ) { - test.deepEqual( [ a, b, c ], [ 'Dexter', 'is', 'here!' ], 'keeping arguments in the spied call' ); - }; - - Dexter.spy( this.foo, 'otherBar' ); - - this.foo.otherBar( 'Dexter', 'is', 'here!' ); - test.done(); - }, - 'callback()': function( test ) { - test.expect( 6 ); - 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' ); - }; - - this.foo.bar( test, 1, 2, 3 ); - - this.spy.restore(); - - this.spy = Dexter.spy( this.foo, 'bar', function() { - test.ok( true, 'callback can be set at spy creation' ); - return 'bar!'; - }); - - test.strictEqual( this.foo.bar(test), 'foo!', 'spy preserves returned value' ); - test.done(); - }, - 'callback() order': function( test ) { - test.expect( 1 ); - var foo = ''; - - Dexter.__bar__ = function() { - foo = 'a'; - }; - - Dexter.spy( Dexter, '__bar__', function() { - foo += 'b'; - }); - - Dexter.__bar__(); - - test.strictEqual( foo, 'ab', 'callback called after spied function' ); - test.done(); - } - }; - -}()); diff --git a/test/unit/environment.js b/test/unit/environment.js index 21f3e11..fb23602 100644 --- a/test/unit/environment.js +++ b/test/unit/environment.js @@ -1,19 +1,27 @@ /* API Ref: http://api.qunitjs.com */ -/* globals Dexter:true, QUnit: true, expect: true */ +/* globals QUnit: true */ -QUnit.module( 'Environment' ); +(function() { -QUnit.test( 'Dexter is here!', function( assert ) { - expect( 2 ); + var Dexter; - assert.equal( typeof( Dexter ), 'object', 'Dexter is an object' ); - assert.ok( Dexter, 'Dexter is not falsy' ); -}); + // NPM scope + if ( !Dexter && typeof module !== 'undefined' && module.exports ) { + Dexter = require( '../../src/Dexter.js' ); + } else { + Dexter = window.Dexter; + } -QUnit.test( 'Dexter functions', function( assert ) { - expect( 3 ); + QUnit.module( 'Environment' ); - assert.equal( typeof( Dexter.spy ), 'function', 'Dexter.spy is a function' ); - assert.equal( typeof( Dexter.fake ), 'function', 'Dexter.fake is a function' ); - assert.equal( typeof( Dexter.fakeXHR ), 'function', 'Dexter.fakeXHR is a function' ); -}); + QUnit.test( 'Dexter is here!', function( assert ) { + assert.equal( typeof( Dexter ), 'object', 'Dexter is an object' ); + assert.ok( Dexter, 'Dexter is not falsy' ); + }); + + QUnit.test( 'Dexter functions', function( assert ) { + assert.equal( typeof( Dexter.spy ), 'function', 'Dexter.spy is a function' ); + assert.equal( typeof( Dexter.fake ), 'function', 'Dexter.fake is a function' ); + }); + +}()); diff --git a/test/unit/fake.js b/test/unit/fake.js index e77a6f3..30fef32 100644 --- a/test/unit/fake.js +++ b/test/unit/fake.js @@ -1,66 +1,79 @@ /* API Ref: http://api.qunitjs.com */ -/* globals Dexter:true, QUnit: true, expect: true */ +/* globals QUnit: true, expect: true */ -QUnit.module( 'Dexter fake', { - setup: function( assert ) { - this.foo = {}; - this.foo.bar = function() { - assert.ok( false, 'fake shoud not call original method' ); - }; - this.fake = Dexter.fake( this.foo, 'bar' ); - }, - teardown: function() { - Dexter.restore(); +(function() { + + var Dexter; + + // NPM scope + if ( !Dexter && typeof module !== 'undefined' && module.exports ) { + Dexter = require( '../../src/Dexter.js' ); + } else { + Dexter = window.Dexter; } -}); -QUnit.test( 'returned object', 2, function( assert ) { - expect( 2 ); + QUnit.module( 'Dexter fake', { + setup: function( assert ) { + this.foo = {}; + this.foo.bar = function() { + assert.ok( false, 'fake shoud not call original method' ); + }; + this.fake = Dexter.fake( this.foo, 'bar' ); + }, + teardown: function() { + Dexter.restore(); + } + }); - assert.equal( typeof( this.fake ), 'object', 'Dexter.fake returns and object' ); - assert.ok( this.fake.isActive, 'fake.isActive === true' ); -}); + QUnit.test( 'returned object', 2, function( assert ) { + expect( 2 ); -QUnit.test( 'call count', function( assert ) { - expect( 11 ); + assert.equal( typeof( this.fake ), 'object', 'Dexter.fake returns and object' ); + assert.ok( this.fake.isActive, 'fake.isActive === true' ); + }); - for ( var i = 0 ; i < 11 ; ++i ) { - assert.deepEqual( this.fake.called, i, 'fake.called === ' + i ); - this.foo.bar(); - } -}); + QUnit.test( 'call count', function( assert ) { + expect( 11 ); -QUnit.test( 'restore()', function( assert ) { - this.foo.otherBar = function() { - assert.ok( true, 'fake restore objects' ); - }; + for ( var i = 0 ; i < 11 ; ++i ) { + assert.deepEqual( this.fake.called, i, 'fake.called === ' + i ); + this.foo.bar(); + } + }); + + QUnit.test( 'restore()', function( assert ) { + this.foo.otherBar = function() { + assert.ok( true, 'fake restore objects' ); + }; - var fake = Dexter.fake( this.foo, 'otherBar' ); + var fake = Dexter.fake( this.foo, 'otherBar' ); - fake.restore(); + fake.restore(); - this.foo.otherBar(); + this.foo.otherBar(); - assert.deepEqual( fake.called, 0, 'restored fake should not be affected by further calls' ); - assert.deepEqual( fake.isActive, false, 'fake.isActive === false after restoring' ); -}); + assert.deepEqual( fake.called, 0, 'restored fake should not be affected by further calls' ); + assert.deepEqual( fake.isActive, false, 'fake.isActive === false after restoring' ); + }); + + QUnit.test( 'callback()', function( assert ) { + expect( 4 ); -QUnit.test( 'callback()', function( assert ) { - expect( 4 ); + this.fake.callback = function( a, b, c ) { + assert.ok( true, '.callback is set' ); + assert.deepEqual( [ a, b, c ], [ 1, 2, 3 ], 'callback arguments working' ); + }; - this.fake.callback = function( a, b, c ) { - assert.ok( true, '.callback is set' ); - assert.deepEqual( [ a, b, c ], [ 1, 2, 3 ], 'callback arguments working' ); - }; + this.foo.bar( 1, 2, 3 ); - this.foo.bar( 1, 2, 3 ); + this.fake.restore(); - this.fake.restore(); + this.fake = Dexter.fake( this.foo, 'bar', function() { + assert.ok( true, 'callback can be set at fake creation' ); + return 17; + }); - this.fake = Dexter.fake( this.foo, 'bar', function() { - assert.ok( true, 'callback can be set at fake creation' ); - return 17; + assert.strictEqual( this.foo.bar(), 17, 'fake returned value set in callback' ); }); - assert.strictEqual( this.foo.bar(), 17, 'fake returned value set in callback' ); -}); +}()); diff --git a/test/unit/restore.js b/test/unit/restore.js index b124abf..016a562 100644 --- a/test/unit/restore.js +++ b/test/unit/restore.js @@ -1,59 +1,72 @@ /* API Ref: http://api.qunitjs.com */ -/* globals Dexter:true, QUnit: true, expect: true */ - -QUnit.module( 'Dexter.restore()', { - setup: function() { - this.myMock1 = function() {}; - this.myMock2 = function() {}; - this.myMock3 = function() {}; - - this.fakes = []; - this.fakes.push( Dexter.fake( this, 'myMock1' ) ); - this.fakes.push( Dexter.fake( this, 'myMock2' ) ); - this.fakes.push( Dexter.spy( this, 'myMock3' ) ); - }, - teardown: function() { - while ( this.fakes.length ) { - this.fakes.pop().restore(); - } - } -}); +/* globals QUnit: true, expect: true */ -QUnit.test( 'storing methods', function( assert ) { - expect( 3 ); +(function() { - var fakes = this.fakes, - stored = Dexter.stored, - item; + var Dexter; - while ( fakes.length ) { - item = fakes.pop(); - assert.strictEqual( stored.pop(), item, 'Dexter stored item' ); - - item.restore(); + // NPM scope + if ( !Dexter && typeof module !== 'undefined' && module.exports ) { + Dexter = require( '../../src/Dexter.js' ); + } else { + Dexter = window.Dexter; } -}); -QUnit.test( 'restoring', function( assert ) { - assert.ok( Dexter.stored.length >= 3, 'Dexter.stored has items' ); + QUnit.module( 'Dexter.restore()', { + setup: function() { + this.myMock1 = function() {}; + this.myMock2 = function() {}; + this.myMock3 = function() {}; - assert.ok( Dexter.restore(), 'Dexter.restore() => true' ); + this.fakes = []; + this.fakes.push( Dexter.fake( this, 'myMock1' ) ); + this.fakes.push( Dexter.fake( this, 'myMock2' ) ); + this.fakes.push( Dexter.spy( this, 'myMock3' ) ); + }, + teardown: function() { + while ( this.fakes.length ) { + this.fakes.pop().restore(); + } + } + }); - assert.strictEqual( Dexter.stored.length, 0, 'Dexter.stored empty after Dexter.restore()' ); -}); + QUnit.test( 'storing methods', function( assert ) { + expect( 3 ); -QUnit.test( 'restoring for sure', function( assert ) { - expect( 1 ); + var fakes = this.fakes, + stored = Dexter.stored, + item; - this.myFn = function() { - assert.ok( true, 'restored function working' ); - }; + while ( fakes.length ) { + item = fakes.pop(); + assert.strictEqual( stored.pop(), item, 'Dexter stored item' ); - Dexter.fake( this, 'myFn', function() { - throw 'do not call me'; + item.restore(); + } }); - Dexter.restore(); + QUnit.test( 'restoring', function( assert ) { + assert.ok( Dexter.stored.length >= 3, 'Dexter.stored has items' ); + + assert.ok( Dexter.restore(), 'Dexter.restore() => true' ); + + assert.strictEqual( Dexter.stored.length, 0, 'Dexter.stored empty after Dexter.restore()' ); + }); + + QUnit.test( 'restoring for sure', function( assert ) { + expect( 1 ); + + this.myFn = function() { + assert.ok( true, 'restored function working' ); + }; + + Dexter.fake( this, 'myFn', function() { + throw 'do not call me'; + }); + + Dexter.restore(); + + this.myFn(); + }); - this.myFn(); -}); +}()); diff --git a/test/unit/spy.js b/test/unit/spy.js index 6f566c2..afd6108 100644 --- a/test/unit/spy.js +++ b/test/unit/spy.js @@ -1,108 +1,121 @@ /* API Ref: http://api.qunitjs.com */ -/* globals Dexter:true, QUnit: true, expect: true */ - -QUnit.module( 'Dexter Spy', { - setup: function( assert ) { - this.foo = {}; - this.foo.bar = function() { - assert.ok( true, 'spy preserve method calling' ); - return 'foo!'; - }; - this.spy = Dexter.spy( this.foo, 'bar' ); - }, - teardown: function() { - Dexter.restore(); - } -}); +/* globals QUnit: true, expect: true */ -QUnit.test( 'returned object', function( assert ) { - expect( 5 ); +(function() { - assert.equal( typeof( this.spy ), 'object', 'Dexter.spy returns and object' ); - assert.ok( this.spy.isActive, 'spy.isActive === true' ); + var Dexter; - assert.throws(function() { - Dexter.spy( this.foo, 'whateverDoesntExist' ); - }, 'raises an error if method doesnt exist' ); - - assert.throws(function() { - Dexter.spy(); - }, 'raises an error without arguments' ); + // NPM scope + if ( !Dexter && typeof module !== 'undefined' && module.exports ) { + Dexter = require( '../../src/Dexter.js' ); + } else { + Dexter = window.Dexter; + } + + QUnit.module( 'Dexter Spy', { + setup: function( assert ) { + this.foo = {}; + this.foo.bar = function() { + assert.ok( true, 'spy preserve method calling' ); + return 'foo!'; + }; + this.spy = Dexter.spy( this.foo, 'bar' ); + }, + teardown: function() { + Dexter.restore(); + } + }); - assert.throws(function() { - Dexter.spy( this.foo, function() {} ); - }, 'raises an error if method name isn\'t a string' ); + QUnit.test( 'returned object', function( assert ) { + expect( 5 ); -}); + assert.equal( typeof( this.spy ), 'object', 'Dexter.spy returns and object' ); + assert.ok( this.spy.isActive, 'spy.isActive === true' ); -QUnit.test( 'restore()', function( assert ) { - expect( 3 ); + assert.throws(function() { + Dexter.spy( this.foo, 'whateverDoesntExist' ); + }, 'raises an error if method doesnt exist' ); + + assert.throws(function() { + Dexter.spy(); + }, 'raises an error without arguments' ); - this.spy.restore(); + assert.throws(function() { + Dexter.spy( this.foo, function() {} ); + }, 'raises an error if method name isn\'t a string' ); - this.foo.bar(); + }); - assert.deepEqual( this.spy.called, 0, 'restored spy should not be affected by further calls' ); - assert.deepEqual( this.spy.isActive, false, 'spy.isActive === false after restoring' ); -}); + QUnit.test( 'restore()', function( assert ) { + expect( 3 ); -QUnit.test( 'call count', function( assert ) { - expect( 22 ); + this.spy.restore(); - for ( var i = 0 ; i < 11 ; ++i ) { - assert.deepEqual( this.spy.called, i, 'spy.called === ' + i ); this.foo.bar(); - } -}); -QUnit.test( 'arguments', function( assert ) { - expect( 1 ); + assert.deepEqual( this.spy.called, 0, 'restored spy should not be affected by further calls' ); + assert.deepEqual( this.spy.isActive, false, 'spy.isActive === false after restoring' ); + }); - this.foo.otherBar = function( a, b, c ) { - assert.deepEqual( [ a, b, c ], [ 'Dexter', 'is', 'here!' ], 'keeping arguments in the spied call' ); - }; + QUnit.test( 'call count', function( assert ) { + expect( 22 ); - var spy = Dexter.spy( this.foo, 'otherBar' ); + for ( var i = 0 ; i < 11 ; ++i ) { + assert.deepEqual( this.spy.called, i, 'spy.called === ' + i ); + this.foo.bar(); + } + }); - this.foo.otherBar( 'Dexter', 'is', 'here!' ); + QUnit.test( 'arguments', function( assert ) { + expect( 1 ); - spy.restore(); -}); + this.foo.otherBar = function( a, b, c ) { + assert.deepEqual( [ a, b, c ], [ 'Dexter', 'is', 'here!' ], 'keeping arguments in the spied call' ); + }; -QUnit.test( 'callback()', function( assert ) { - expect( 6 ); + var spy = Dexter.spy( this.foo, 'otherBar' ); - this.spy.callback = function( a, b, c ) { - assert.ok( true, '.callback is set' ); - assert.deepEqual( [ a, b, c ], [ 1, 2, 3 ], 'callback arguments working' ); - }; + this.foo.otherBar( 'Dexter', 'is', 'here!' ); - this.foo.bar( 1, 2, 3 ); + spy.restore(); + }); + + QUnit.test( 'callback()', function( assert ) { + expect( 6 ); + + this.spy.callback = function( a, b, c ) { + assert.ok( true, '.callback is set' ); + assert.deepEqual( [ a, b, c ], [ 1, 2, 3 ], 'callback arguments working' ); + }; + + this.foo.bar( 1, 2, 3 ); - this.spy.restore(); + this.spy.restore(); - this.spy = Dexter.spy( this.foo, 'bar', function() { - assert.ok( true, 'callback can be set at spy creation' ); - return 'bar!'; + this.spy = Dexter.spy( this.foo, 'bar', function() { + assert.ok( true, 'callback can be set at spy creation' ); + return 'bar!'; + }); + + assert.strictEqual( this.foo.bar(), 'foo!', 'spy preserves returned value' ); }); - assert.strictEqual( this.foo.bar(), 'foo!', 'spy preserves returned value' ); -}); + QUnit.test( 'callback() order', function( assert ) { + expect( 1 ); + + var foo = ''; -QUnit.test( 'callback() order', function( assert ) { - expect( 1 ); + Dexter.__bar__ = function() { + foo = 'a'; + }; - var foo = ''; + Dexter.spy( Dexter, '__bar__', function() { + foo += 'b'; + }); - Dexter.__bar__ = function() { - foo = 'a'; - }; + Dexter.__bar__(); - Dexter.spy( Dexter, '__bar__', function() { - foo += 'b'; + assert.strictEqual( foo, 'ab', 'callback called after spied function' ); }); - Dexter.__bar__(); - - assert.strictEqual( foo, 'ab', 'callback called after spied function' ); -}); +}());