jstonic/test/then/ThenTest.js

99 lines
2.5 KiB
JavaScript

/**
* Tests vanilla Thenable
*
* Copyright (C) 2014 Mike Gerwitz
*
* This file is part of jsTonic.
*
* jstonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
let Class = require( 'easejs' ).Class,
Sut = require( '../../' ).then.Then,
Thenable = require( '../../' ).then.Thenable,
expect = require( 'chai' ).expect,
Conform = require( './ThenableTestConform' ),
Stub = Class.use( Sut ).extend(
{
_andThenVal: null,
__construct( atv )
{
this._andThenVal = atv;
},
'protected andThen'()
{
return this._andThenVal || this;
},
stubFulfill( value ) { this.fulfill( value ); },
stubReject( reason ) { this.reject( reason ); },
} ),
DummyThen = Class.implement( Thenable ).extend(
{
then( _, __ )
{
}
} );
let accept = then => then.stubFulfill( 'something' ),
reject = then => then.stubReject( Error( 'reason' ) );
/**
* Note that we test only the requirements that are not handled by the
* `Thenable` conformance test case.
*/
describe( 'then.Then', () =>
{
// `Thenable` conformance
Conform( () => Stub(), accept, reject );
describe( '#then', () =>
{
describe( 'return Thenable', () =>
{
/**
* The implementation is wholly responsible for the
* instantiation of the chained `Thenable`.
*/
it( 'is the result of applying #andThen', () =>
expect(
Class.isA( DummyThen,
Stub( DummyThen() ).then() ) )
.to.be.true );
it( 'is returned by reference', () =>
{
let t = DummyThen();
expect( Stub( t ).then() ).to.equal( t );
} );
} );
} );
describe( '#fulfill', () =>
{
it( '
} );
} );