Skip to content

Commit 3ce4e02

Browse files
Mac Minimichaelbe812
authored andcommitted
fix: improve tests
1 parent 9c5da8e commit 3ce4e02

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

packages/plugin-openapi/src/lib/openapi-tools-generator.spec.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ describe('OpenApiToolsGenerator', () => {
117117
outputPath: 'src/generated',
118118
};
119119

120-
const generatePromise = generator.generate(options, mockContext);
121-
122-
// Simulate failure on all attempts
120+
// Simulate failure on all attempts - set up mock BEFORE calling generate
123121
let attemptCount = 0;
124122
(spawn as jest.Mock).mockImplementation(() => {
125123
attemptCount++;
@@ -129,7 +127,7 @@ describe('OpenApiToolsGenerator', () => {
129127
return childProcess;
130128
});
131129

132-
await expect(generatePromise).rejects.toThrow(
130+
await expect(generator.generate(options, mockContext)).rejects.toThrow(
133131
'Failed to generate code after 1 attempts'
134132
);
135133
expect(attemptCount).toBe(1);
@@ -141,9 +139,7 @@ describe('OpenApiToolsGenerator', () => {
141139
outputPath: 'src/generated',
142140
};
143141

144-
const generatePromise = generator.generate(options, mockContext);
145-
146-
// Simulate error on all attempts
142+
// Simulate error on all attempts - set up mock BEFORE calling generate
147143
let attemptCount = 0;
148144
(spawn as jest.Mock).mockImplementation(() => {
149145
attemptCount++;
@@ -154,7 +150,7 @@ describe('OpenApiToolsGenerator', () => {
154150
return childProcess;
155151
});
156152

157-
await expect(generatePromise).rejects.toThrow(
153+
await expect(generator.generate(options, mockContext)).rejects.toThrow(
158154
'Failed to generate code after 1 attempts'
159155
);
160156
expect(attemptCount).toBe(1);
@@ -273,9 +269,7 @@ describe('OpenApiToolsGenerator', () => {
273269
outputPath: 'src/api',
274270
} as unknown as OpenApiGeneratorOptions & GenerateOptionsBase;
275271

276-
const generatePromise = generator.generate(options, mockContext);
277-
278-
// Mock spawn to simulate first succeeding, second failing
272+
// Mock spawn to simulate first succeeding, second failing - set up mock BEFORE calling generate
279273
let callCount = 0;
280274
(spawn as jest.Mock).mockImplementation(() => {
281275
callCount++;
@@ -293,7 +287,7 @@ describe('OpenApiToolsGenerator', () => {
293287
return childProcess;
294288
});
295289

296-
await expect(generatePromise).rejects.toThrow(
290+
await expect(generator.generate(options, mockContext)).rejects.toThrow(
297291
'Failed to generate code after 1 attempts'
298292
);
299293
}, 10000);

0 commit comments

Comments
 (0)