kobezzza, вот что получилось в итоге, теперь я понял почему нужно писать тесты
describe('new ModalJS', function() {
var modal;
it( 'new Object', function() {
modal = new ModalJS();
expect( typeof modal )
.toBe( "object" );
});
it ( "Create overlay", function () {
expect ( isHTMLElement( modal.overlay) )
.toBe( true );
expect ( modal.overlay.parentElement )
.toBe( document.body );
} );
});
function isHTMLElement( elem ) {
return (typeof elem === "object") &&
(elem.nodeType === 1) && (typeof elem.style === "object") &&
(typeof elem.ownerDocument ==="object");
}
describe ( "Methods", function () {
var modal, win;
function resetWindow ( ) {
win = document.getElementById( "modal-test-win");
win2 = document.getElementById( "modal-test-win2");
modal = new ModalJS( {
NotUseAnimate: true
} ).setWindow ( win || win2 );
}
resetWindow();
it( "set window", function () {
expect( modal.setWindow ( win ))
.toEqual ( modal );
});
it ( "Show window", function ( ) {
expect ( modal.show () )
.toBe ( true );
} );
it ( "Hide window", function ( ) {
expect ( modal.hide () )
.toBe ( true );
} );
it ( "Window destroy", function ( ) {
expect ( modal.destroy( ) )
.toBe ( true );
} );
it ( "Window destroy [remove Window]", function ( ) {
resetWindow ( );
expect ( modal.destroy( true ) )
.toBe ( true );
expect ( modal.window )
.toBeUndefined();
} );
} );
describe ( "Async animate", function ( ) {
var win2 = document.getElementById( "modal-test-win2"),
modal = new ModalJS().setWindow ( win2 );
beforeEach( function ( done ) {
modal.on ( "showed", done );
modal.show();
} );
it ( "Hide window", function ( done ) {
modal.on ( "closed", done );
modal.hide();
} );
});