@@ -22,6 +22,21 @@ const baseSlots = {};
2222let mockProps = { } ;
2323let mockSlots = { } ;
2424
25+ // Mock native <dialog> methods not supported in JSDOM
26+ beforeAll ( ( ) => {
27+ HTMLDialogElement . prototype . showModal = vi . fn ( function ( ) {
28+ this . setAttribute ( 'open' , '' ) ;
29+ } ) ;
30+ HTMLDialogElement . prototype . close = vi . fn ( function ( ) {
31+ this . removeAttribute ( 'open' ) ;
32+ } ) ;
33+ } ) ;
34+
35+ afterAll ( ( ) => {
36+ delete HTMLDialogElement . prototype . showModal ;
37+ delete HTMLDialogElement . prototype . close ;
38+ } ) ;
39+
2540describe ( 'DtModal Tests' , ( ) => {
2641 let wrapper ;
2742 let closeBtn ;
@@ -47,6 +62,7 @@ describe('DtModal Tests', () => {
4762 } ;
4863
4964 beforeEach ( ( ) => {
65+ vi . clearAllMocks ( ) ;
5066 updateWrapper ( ) ;
5167 } ) ;
5268
@@ -56,17 +72,15 @@ describe('DtModal Tests', () => {
5672 wrapper . unmount ( ) ;
5773 } ) ;
5874
59- afterAll ( ( ) => {
60- // Restore RequestAnimationFrame and cancelAnimationFrame
61- global . requestAnimationFrame = undefined ;
62- global . cancelAnimationFrame = undefined ;
63- } ) ;
64-
6575 describe ( 'Presentation Tests' , ( ) => {
6676 it ( 'should render the component' , ( ) => {
6777 expect ( wrapper . exists ( ) ) . toBe ( true ) ;
6878 } ) ;
6979
80+ it ( 'should render using a native dialog element' , ( ) => {
81+ expect ( overlay . element . tagName ) . toBe ( 'DIALOG' ) ;
82+ } ) ;
83+
7084 it ( 'should render the title content' , ( ) => {
7185 expect ( title . exists ( ) ) . toBe ( true ) ;
7286 expect ( title . text ( ) ) . toEqual ( MOCK_MODAL_TITLE ) ;
@@ -94,6 +108,10 @@ describe('DtModal Tests', () => {
94108 expect ( banner . classes ( MODAL_BANNER_KINDS [ DtModal . props . bannerKind . default ] ) ) . toBe ( true ) ;
95109 } ) ;
96110
111+ it ( 'Should call showModal when show is true' , ( ) => {
112+ expect ( overlay . element . showModal ) . toHaveBeenCalled ( ) ;
113+ } ) ;
114+
97115 describe ( 'When hideClose prop is true' , ( ) => {
98116 beforeEach ( async ( ) => {
99117 mockProps = { ...mockProps , hideClose : true } ;
@@ -162,14 +180,20 @@ describe('DtModal Tests', () => {
162180 expect ( wrapper . emitted ( ) [ SYNC_EVENT_NAME ] [ 0 ] [ 0 ] ) . toBe ( false ) ;
163181 } ) ;
164182
165- it ( 'Should emit a sync-able update event when escape key is pressed ' , async ( ) => {
183+ it ( 'Should emit a sync-able update event when cancel event fires (escape key) ' , async ( ) => {
166184 expect ( wrapper . emitted ( SYNC_EVENT_NAME ) ) . toBeFalsy ( ) ;
167185
168- await overlay . trigger ( 'keydown' , { code : 'Escape' } ) ;
186+ await overlay . trigger ( 'cancel' ) ;
169187
170188 expect ( wrapper . emitted ( ) [ SYNC_EVENT_NAME ] . length ) . toBe ( 1 ) ;
171189 expect ( wrapper . emitted ( ) [ SYNC_EVENT_NAME ] [ 0 ] [ 0 ] ) . toBe ( false ) ;
172190 } ) ;
191+
192+ it ( 'Should emit keydown event to parent' , async ( ) => {
193+ await overlay . trigger ( 'keydown' , { code : 'Escape' } ) ;
194+
195+ expect ( wrapper . emitted ( ) . keydown ) . toBeTruthy ( ) ;
196+ } ) ;
173197 } ) ;
174198
175199 describe ( 'Extendability Tests' , ( ) => {
0 commit comments