@@ -44,26 +44,53 @@ global.displayTestStats = function() {
4444} ;
4545
4646/**
47- * Wraps test functions that use both `async` and a `done` callback, which Jasmine
47+ * Wraps test functions that use both `async` and a `done` callback, which Jasmine 5
4848 * does not support. This converts `async (done) => { ... }` to a promise-based
4949 * function so Jasmine does not throw:
5050 * "An asynchronous before/it/after function was defined with the async keyword
5151 * but also took a done callback."
5252 */
5353global . normalizeAsyncTests = function ( ) {
54- const originalSpecConstructor = jasmine . Spec ;
55- jasmine . Spec = function ( attrs ) {
56- const spec = new originalSpecConstructor ( attrs ) ;
57- const originalTestFn = spec . queueableFn . fn ;
58- if ( originalTestFn . length > 0 ) {
59- spec . queueableFn . fn = function ( ) {
54+ function wrapDoneCallback ( fn ) {
55+ if ( fn . length > 0 ) {
56+ return function ( ) {
6057 return new Promise ( ( resolve ) => {
61- originalTestFn ( resolve ) ;
58+ fn . call ( this , resolve ) ;
6259 } ) ;
6360 } ;
6461 }
62+ return fn ;
63+ }
64+
65+ // Wrap it() specs
66+ const originalSpecConstructor = jasmine . Spec ;
67+ jasmine . Spec = function ( attrs ) {
68+ const spec = new originalSpecConstructor ( attrs ) ;
69+ spec . queueableFn . fn = wrapDoneCallback ( spec . queueableFn . fn ) ;
6570 return spec ;
6671 } ;
72+
73+ // Wrap beforeEach/afterEach/beforeAll/afterAll
74+ const originalBeforeEach = jasmine . Suite . prototype . beforeEach ;
75+ jasmine . Suite . prototype . beforeEach = function ( fn ) {
76+ fn . fn = wrapDoneCallback ( fn . fn ) ;
77+ return originalBeforeEach . call ( this , fn ) ;
78+ } ;
79+ const originalAfterEach = jasmine . Suite . prototype . afterEach ;
80+ jasmine . Suite . prototype . afterEach = function ( fn ) {
81+ fn . fn = wrapDoneCallback ( fn . fn ) ;
82+ return originalAfterEach . call ( this , fn ) ;
83+ } ;
84+ const originalBeforeAll = jasmine . Suite . prototype . beforeAll ;
85+ jasmine . Suite . prototype . beforeAll = function ( fn ) {
86+ fn . fn = wrapDoneCallback ( fn . fn ) ;
87+ return originalBeforeAll . call ( this , fn ) ;
88+ } ;
89+ const originalAfterAll = jasmine . Suite . prototype . afterAll ;
90+ jasmine . Suite . prototype . afterAll = function ( fn ) {
91+ fn . fn = wrapDoneCallback ( fn . fn ) ;
92+ return originalAfterAll . call ( this , fn ) ;
93+ } ;
6794} ;
6895
6996module . exports = CurrentSpecReporter ;
0 commit comments