33 * them on their own using `ddescribe` works okay. Therefore this test is ignored in general unless specifically testing
44 * this directive, in which case change `xdescribe` to `ddescribe`.
55 */
6- xdescribe ( 'dirDisqus directive' , function ( ) {
6+ describe ( 'dirDisqus directive' , function ( ) {
77 var scope ,
88 elem ,
99 compiled ,
@@ -19,6 +19,7 @@ xdescribe('dirDisqus directive', function() {
1919 'disqus-category-id="{{ post.catId }}"' +
2020 'disqus-disable-mobile="false"' +
2121 'disqus-config-language="{{ post.lang }}"' +
22+ 'disqus-on-ready="ready()"' +
2223 'ready-to-bind="{{ loaded }}">' +
2324 '</dir-disqus>' ;
2425
@@ -33,6 +34,10 @@ xdescribe('dirDisqus directive', function() {
3334 lang : 'en'
3435 } ;
3536 scope . loaded = false ;
37+ scope . readyCalled = false ;
38+ scope . ready = function ( ) {
39+ scope . readyCalled = true ;
40+ } ;
3641
3742 //get the jqLite or jQuery element
3843 elem = angular . element ( html ) ;
@@ -41,14 +46,20 @@ xdescribe('dirDisqus directive', function() {
4146 compiled = $compile ( elem ) ;
4247
4348 //run the compiled view.
44- compiled ( scope ) ;
49+ var element = compiled ( scope ) ;
50+
51+ var div = document . createElement ( "div" ) ;
52+ div . innerHTML = element . html ( ) ;
4553
46- //call digest on the scope!
47- scope . $digest ( ) ;
54+ // Just add disqus to document - it is needed to work embed.js properly
55+ document . getElementsByTagName ( 'body' ) [ 0 ] . appendChild ( div ) ;
4856 } ) ;
4957 } ) ;
5058
5159 it ( 'should not do anything when ready to bind is false' , function ( ) {
60+ //call digest on the scope!
61+ scope . $digest ( ) ;
62+
5263 expect ( elem . find ( "#disqus_thread" ) ) . toBeTruthy ( ) ;
5364 expect ( $ ( "script[src='//shortname.disqus.com/embed.js']" ) . length ) . toEqual ( 0 ) ;
5465 expect ( window . disqus_shortname ) . toBeFalsy ( ) ;
@@ -57,6 +68,7 @@ xdescribe('dirDisqus directive', function() {
5768 expect ( window . disqus_url ) . toBeFalsy ( ) ;
5869 expect ( window . disqus_category_id ) . toBeFalsy ( ) ;
5970 expect ( window . disqus_disable_mobile ) . toBeFalsy ( ) ;
71+ expect ( scope . readyCalled ) . toBeFalsy ( ) ;
6072 expect ( window . language ) . toBeFalsy ( ) ;
6173 } ) ;
6274
@@ -70,7 +82,16 @@ xdescribe('dirDisqus directive', function() {
7082 expect ( window . disqus_url ) . toEqual ( 'http://www.test.com' ) ;
7183 expect ( window . disqus_category_id ) . toEqual ( '999' ) ;
7284 expect ( window . disqus_disable_mobile ) . toEqual ( 'false' ) ;
85+
86+ window . page = { } ;
87+ window . callbacks = { } ;
7388 window . disqus_config ( ) ;
89+
7490 expect ( window . language ) . toEqual ( 'en' ) ;
91+ expect ( window . callbacks . onReady ) . toBeDefined ( ) ;
92+ expect ( window . callbacks . onReady . length ) . toEqual ( 1 ) ;
93+ window . callbacks . onReady [ 0 ] ( ) ;
94+ expect ( scope . readyCalled ) . toBeTruthy ( ) ;
95+
7596 } ) ;
7697} ) ;
0 commit comments