Repository: jquery/jquery
File: test/unit/deferred.js (JavaScript)

Code before:
	assert.expect( 4 );

	var value1, value2, value3,
		defer = jQuery.Deferred(),
		piped = defer.catch(function( a, b ) {
			return a * b;
		}),
		done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );

	piped.done(function( result ) {
		value3 = result;
	});

	defer.fail(function( a, b ) {
		value1 = a;
		value2 = b;
	});

	defer.reject( 2, 3 ).catch(function() {
		assert.strictEqual( value1, 2, "first reject value ok" );
		assert.strictEqual( value2, 3, "second reject value ok" );
		assert.strictEqual( value3, 6, "result of filter ok" );
		done.pop().call();
	});

	jQuery.Deferred().resolve().catch(function() {
		assert.ok( false, "then should not be called on resolve" );
	}).then( done.pop() );

	jQuery.Deferred().reject().catch(jQuery.noop ).done(function( value ) {
		assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
		done.pop().call();
	});
});

test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert ) {

	assert.expect( 4 );

	var value1, value2, value3,
		defer = jQuery.Deferred(),
		piped = defer.pipe( null, function( a, b ) {
			return a * b;
		}),
		done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );

	piped.fail(function( result ) {
		value3 = result;
	});

	defer.fail(function( a, b ) {

Review comment (bug):
@jaubourg HI! So you come out of the woodwork when it's a style
discussion!? ;)

On Mon, Jul 6, 2015 at 9:51 PM Julian Aubourg notifications@github.com
wrote:

> In test/unit/deferred.js
> https://github.com/jquery/jquery/pull/2451#discussion_r34002121:
> 
> > -       value3 = result;
> > -   });
> >   +
> > -   defer.fail(function( a, b ) {
> > -       value1 = a;
> > -       value2 = b;
> > -   });
> >   +
> > -   defer.reject( 2, 3 ).catch(function() {
> > -       assert.strictEqual( value1, 2, "first reject value ok" );
> > -       assert.strictEqual( value2, 3, "second reject value ok" );
> > -       assert.strictEqual( value3, 6, "result of filter ok" );
> > -       done.pop().call();
> > -   });
> >   +
> > -   jQuery.Deferred().resolve().catch(function() {
> 
> My 2 cents.
> 
> I've been using the "space-everywhere-no-exception" approach in my
> projects for 2 years now. Found it painful at first but got used to it and
> I find it much easier to comply with and explain to coworkers.
> 
> Like @markelog https://github.com/markelog said, it's all just
> conventions and endless debates about them. Still, for the sake of
> simplicity in applying the code style and clarity in explaining it to
> contributors, the no-exception approach has always been a big win in
> anything I worked on.
> 
> Oh, and hi!
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/jquery/jquery/pull/2451/files#r34002121.


Code after:
	assert.expect( 4 );

	var value1, value2, value3,
		defer = jQuery.Deferred(),
		piped = defer.catch(function( a, b ) {
			return a * b;
		}),
		done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );

	piped.done(function( result ) {
		value3 = result;
	});

	defer.fail(function( a, b ) {
		value1 = a;
		value2 = b;
	});

	defer.reject( 2, 3 ).catch(function() {
		assert.strictEqual( value1, 2, "first reject value ok" );
		assert.strictEqual( value2, 3, "second reject value ok" );
		assert.strictEqual( value3, 6, "result of filter ok" );
		done.pop().call();
	});

	jQuery.Deferred().resolve().catch(function() {
		assert.ok( false, "then should not be called on resolve" );
	}).then( done.pop() );

	jQuery.Deferred().reject().catch( jQuery.noop ).done(function( value ) {
		assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
		done.pop().call();
	});
});

test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert ) {

	assert.expect( 4 );

	var value1, value2, value3,
		defer = jQuery.Deferred(),
		piped = defer.pipe( null, function( a, b ) {
			return a * b;
		}),
		done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );

	piped.fail(function( result ) {
		value3 = result;
	});

	defer.fail(function( a, b ) {