Skip to content

Commit d23bcbc

Browse files
authored
Add files via upload
1 parent 464d9f5 commit d23bcbc

File tree

1 file changed

+29
-45
lines changed

1 file changed

+29
-45
lines changed

test/unit/manipulation.js

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,66 +3104,50 @@ testIframe(
31043104

31053105
QUnit.test( "should handle custom '_se-custom-destroy' event correctly", function( assert ) {
31063106

3107-
// Set up the HTML structure using innerHTML within #qunit-fixture
3107+
// Define the expected number of assertions
31083108

3109-
assert.expect( 2 );
3109+
assert.expect( 4 );
3110+
3111+
// Set up the HTML structure by appending to the existing fixture
31103112

31113113
var fixture = jQuery( "#qunit-fixture" );
31123114

3113-
fixture.html( `
3114-
<div id="container">
3115-
<div class="guarded removeself" data-elt="one">
3116-
Guarded 1
3117-
</div>
3118-
<div class="guarded" data-elt="two">
3119-
Guarded 2
3120-
</div>
3121-
<div class="guarded" data-elt="three">
3122-
Guarded 3
3123-
</div>
3124-
</div>
3125-
` );
3126-
3127-
// JavaScript code to be tested
3128-
3129-
jQuery.event.special[ "_se-custom-destroy" ] = {
3130-
remove: function( _handleObj ) {
3115+
fixture.append( `
3116+
<div id="container">
3117+
<div class="guarded removeself" data-elt="one">
3118+
Guarded 1
3119+
</div>
3120+
<div class="guarded" data-elt="two">
3121+
Guarded 2
3122+
</div>
3123+
<div class="guarded" data-elt="three">
3124+
Guarded 3
3125+
</div>
3126+
</div>
3127+
` );
3128+
3129+
// Define the custom event handler
3130+
jQuery.event.special[ "_se-custom-destroy" ] = {
3131+
remove: function( _handleObj ) {
31313132
var $t = jQuery( this );
3132-
console.log( $t.data( "elt" ) );
3133+
assert.step( $t.data( "elt" ) );
31333134
if ( $t.is( ".removeself" ) ) {
31343135
$t.remove();
3135-
}
31363136
}
3137+
}
31373138
};
31383139

3139-
// Attach the custom event handler
3140+
// Attach an empty handler to trigger the `remove`
3141+
// logic for the custom event when the element is removed.
31403142

31413143
jQuery( ".guarded" ).on( "_se-custom-destroy", function( ) { } );
31423144

3143-
// Spy on console.log
3144-
3145-
var consoleLog = console.log;
3146-
3147-
var logMessages = [];
3148-
3149-
console.log = function( message ) {
3150-
logMessages.push( message );
3151-
};
3152-
31533145
// Trigger the event by emptying the container
31543146

3155-
jQuery( "#container" ).empty( );
3156-
3157-
// Verify that the elements with class 'removeself' were removed
3158-
3159-
assert.equal( jQuery( ".removeself" ).length, 0, "Elements with class 'removeself' should be removed" );
3147+
jQuery( "#container" ).empty();
31603148

3161-
// Verify console logs
3162-
3163-
assert.deepEqual( logMessages, [ "one", "two", "three" ], "Console logs should match the data-elt attributes" );
3164-
3165-
// Restore console.log
3166-
3167-
console.log = consoleLog;
3149+
// Verify the steps to ensure the expected elements were processed
31683150

3151+
assert.verifySteps( [ "one", "two", "three" ], "Steps should match the data-elt attributes" );
31693152
} );
3153+

0 commit comments

Comments
 (0)