Skip to content

Commit

Permalink
Prettify Test: Fix the test in IE by waiting for the ready event
Browse files Browse the repository at this point in the history
Optimized the test
  • Loading branch information
LaurentGoderre committed Aug 11, 2014
1 parent 71bb869 commit bde4ddd
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/plugins/prettify/test.js
Expand Up @@ -14,8 +14,9 @@
* teardown `after()` for more than one test suite (as is the case below.)
*/
describe( "Prettify test suite", function() {
var spy, $prettify,
$body = wb.doc.find( "body" ),
var spy, callback, $prettify,
$document = wb.doc,
$body = $document.find( "body" ),
sandbox = sinon.sandbox.create();

/*
Expand All @@ -25,11 +26,13 @@ describe( "Prettify test suite", function() {
// Spy on jQuery's trigger method to see how it's called during the plugin's initialization
spy = sandbox.spy( $.prototype, "trigger" );

// Start the tests once the plugin has been initialized
wb.doc.on( "prettyprint.wb-prettify", function() {
done();
// Start the tests once the plugin has been finished processing
$document.on( "wb-ready.wb-prettify", function() {
callback();
});

callback = done;

// Add the test elements
$prettify = $( "<span class='wb-prettify lang-css'>" )
.appendTo( $body )
Expand Down Expand Up @@ -90,7 +93,7 @@ describe( "Prettify test suite", function() {
expect( $("script[src*='/lang-css']") ).to.have.length( 1 );
});

it( "should have not have loaded lang-sql.js syntax file", function() {
it( "should not have loaded lang-sql.js syntax file", function() {
expect( $("script[src*='/lang-sql']") ).to.have.length( 0 );
});
});
Expand All @@ -102,32 +105,30 @@ describe( "Prettify test suite", function() {

before(function( done ) {

//Prettify needs more time in IE to complete, due to the pre from mocha results
this.timeout(5000);

callback = done;

$body.append( "<pre class='test'>" );
$prettify
.removeClass( "wb-prettify-inited" )
.addClass( "lang-sql" )
.addClass( "all-pre" )
.addClass( "linenums" )
.trigger( "wb-init.wb-prettify" );
wb.doc.on( "prettyprint.wb-prettify", function() {
done();
});
});

it( "should have loaded lang-sql.js syntax file", function() {
expect( $("script[src*='/lang-sql']") ).to.have.length( 1 );
});

it( "should have added a .prettyprinted CSS class to all pre elements", function() {
$( "pre:visible" ).each(function() {
expect( this.className.indexOf( "prettyprinted" ) ).to.be.greaterThan( -1 );
});
expect( $( "pre.test.prettyprinted" ).length ).to.be( $( "pre.test" ).length );
});

it( "should have added a .linenums CSS class to all pre elements", function() {
$( "pre:visible" ).each(function() {
expect( this.className.indexOf( "linenums" ) ).to.be.greaterThan( -1 );
});
expect( $( "pre.test.linenums" ).length ).to.be( $( "pre.test" ).length );
});
});

Expand All @@ -138,29 +139,28 @@ describe( "Prettify test suite", function() {

before(function( done ) {

//Prettify needs more time in IE to complete, due to the pre from mocha results
this.timeout(500);

callback = done;

$body.append( "<pre class='test'>" );
$prettify
.removeClass( "wb-prettify-inited" )
.removeClass( "all-pre linenums")
.data({
allpre: true,
linenums: true
})
.trigger( "wb-init.wb-prettify" );
wb.doc.on( "prettyprint.wb-prettify", function() {
done();
});
});

it( "should have added a .prettyprinted CSS class to all pre elements", function() {
$( "pre:visible" ).each(function() {
expect( this.className.indexOf( "prettyprinted" ) ).to.be.greaterThan( -1 );
});
expect( $( "pre.test.prettyprinted" ).length ).to.be( $( "pre.test" ).length );
});

it( "should have added a .linenums CSS class to all pre elements", function() {
$( "pre:visible" ).each(function() {
expect( this.className.indexOf( "linenums" ) ).to.be.greaterThan( -1 );
});
expect( $( "pre.test.linenums" ).length ).to.be( $( "pre.test" ).length );
});
});
});
Expand Down

0 comments on commit bde4ddd

Please sign in to comment.