1- 'use strict' ;
2-
3- require ( 'css-modules-require-hook/preset' ) ;
1+ import { createRequire } from 'node:module' ;
42
3+ const require = createRequire ( import . meta. url ) ;
54const { tryCatch} = require ( 'try-catch' ) ;
65
7- const mockRequire = require ( 'mock-require' ) ;
8-
96const autoGlobals = require ( 'auto-globals' ) ;
10- const { test : tape , stub} = require ( 'supertape' ) ;
7+ const { test : tape , stub} = require ( 'supertape' ) ;
118
129const {
1310 open,
@@ -17,21 +14,15 @@ const {
1714} = require ( './modal' ) ;
1815
1916const { create} = autoGlobals ;
20-
21- const { reRequire, stopAll} = mockRequire ;
22-
2317const test = autoGlobals ( tape ) ;
2418
2519test ( 'modal: open: main exist' , ( t ) => {
2620 const el = { } ;
2721 const query = stub ( ) . returns ( el ) ;
2822
29- mockRequire ( './query' , query ) ;
30-
31- const { open} = mockRequire . reRequire ( './modal' ) ;
32-
33- open ( { } ) ;
34- stopAll ( ) ;
23+ open ( { } , {
24+ query,
25+ } ) ;
3526
3627 t . calledWith ( query , [ 'main' ] , 'should call querySelector' ) ;
3728 t . end ( ) ;
@@ -49,16 +40,11 @@ test('modal: open: beforeShow', (t) => {
4940 called = true ;
5041 } ;
5142
52- mockRequire ( './query' , query ) ;
53-
54- const { open} = reRequire ( './modal' ) ;
55-
5643 open ( { } , {
5744 beforeShow,
45+ query,
5846 } ) ;
5947
60- stopAll ( ) ;
61-
6248 t . calledWithNoArgs ( beforeShow , 'should call querySelector' ) ;
6349 t . end ( ) ;
6450} ) ;
@@ -77,24 +63,16 @@ test('modal: open: showTitle', (t) => {
7763
7864 const showTitle = stub ( ) ;
7965
80- mockRequire ( './query' , query ) ;
81- mockRequire ( './show-title' , showTitle ) ;
82-
83- const { open} = mockRequire . reRequire ( './modal' ) ;
84-
8566 open ( { } , {
67+ query,
68+ showTitle,
8669 beforeShow,
8770 title : 'hello' ,
8871 helpers : {
8972 title : true ,
9073 } ,
9174 } ) ;
9275
93- mockRequire . stop ( './query' ) ;
94- mockRequire . stop ( './show-title' ) ;
95-
96- stopAll ( ) ;
97-
9876 t . calledWith ( showTitle , [ 'hello' , el ] , 'should call querySelector' ) ;
9977 t . end ( ) ;
10078} ) ;
@@ -119,10 +97,6 @@ test('modal: open: images', (t) => {
11997
12098 const parseImages = stub ( ) ;
12199
122- mockRequire ( './query' , query ) ;
123- mockRequire ( './parse-images' , parseImages ) ;
124-
125- const { open} = mockRequire . reRequire ( './modal' ) ;
126100 const images = [ {
127101 title : 'hello' ,
128102 href : 'world' ,
@@ -131,12 +105,11 @@ test('modal: open: images', (t) => {
131105 const afterShow = stub ( ) ;
132106
133107 open ( images , {
108+ query,
134109 afterShow,
110+ parseImages,
135111 } ) ;
136112
137- mockRequire . stop ( './query' ) ;
138- mockRequire . stop ( './parse-images' ) ;
139-
140113 const inner = [ {
141114 title : 'hello' ,
142115 href : 'world' ,
@@ -148,8 +121,6 @@ test('modal: open: images', (t) => {
148121 helpers : { } ,
149122 } ;
150123
151- stopAll ( ) ;
152-
153124 t . calledWith ( parseImages , [ el , inner , options ] , 'should call querySelector' ) ;
154125 t . end ( ) ;
155126} ) ;
@@ -160,7 +131,9 @@ test('modal: onMainClick', (t) => {
160131 stopPropagation : stub ( ) ,
161132 } ;
162133
163- _onMainClick ( overlayClick , e ) ;
134+ const click = _onMainClick ( overlayClick ) ;
135+
136+ click ( e ) ;
164137
165138 t . calledWith ( overlayClick , [ e ] , 'should call overlayClick' ) ;
166139 t . end ( ) ;
@@ -172,7 +145,13 @@ test('modal: onMainClick: no main', (t) => {
172145 target : { } ,
173146 } ;
174147
175- _onMainClick ( overlayClick , e ) ;
148+ const query = stub ( ) ;
149+
150+ const click = _onMainClick ( overlayClick , {
151+ query,
152+ } ) ;
153+
154+ click ( e ) ;
176155
177156 t . notCalled ( overlayClick , 'should not call overlayClick' ) ;
178157 t . end ( ) ;
0 commit comments