Skip to content

Commit dc63c1a

Browse files
committed
fix: change spies to actually work
1 parent a973000 commit dc63c1a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

test/dashboards.test.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,35 @@ describe('Dashboard build', () => {
6565
buildType: BUILD_TYPE.CHANGELOG,
6666
status: VERSION_STATUS.RELEASE,
6767
})
68-
const versionResolverSpy = jest.spyOn(editor.registry as LocalRegistry, 'versionResolver')
69-
const versionDocumentsResolverSpy = jest.spyOn(editor.registry as LocalRegistry, 'versionDocumentsResolver')
70-
const rawDocumentResolverSpy = jest.spyOn(editor.registry as LocalRegistry, 'rawDocumentResolver')
68+
69+
// spy on the builder's wrapper methods that are actually invoked
70+
const versionResolverSpy = jest.spyOn(editor.builder as PackageVersionBuilder, 'versionResolver')
71+
const versionDocumentsResolverSpy = jest.spyOn(editor.builder as PackageVersionBuilder, 'versionDocumentsResolver')
72+
const rawDocumentResolverSpy = jest.spyOn(editor.builder as PackageVersionBuilder, 'rawDocumentResolver')
7173

7274
await editor.run()
7375

74-
// versionResolver(version, packageId)
76+
// versionResolver(version, packageId) - builder's method signature
77+
// Should be called for v1 and v2 dashboard versions
78+
expect(versionResolverSpy).toHaveBeenCalled()
7579
versionResolverSpy.mock.calls.forEach(args => {
76-
// args: [packageId = '', version]
77-
expect(args[1]).toBeTruthy()
80+
expect(args[0]).toBeTruthy() // version should not be empty
81+
expect(args[1]).toBeTruthy() // packageId should not be empty
7882
})
7983

80-
// versionDocumentsResolver(version, packageId)
84+
// versionDocumentsResolver(version, packageId, apiType?)
85+
// Should be called for referenced packages (pckg1/v1 and pckg2/v2)
86+
expect(versionDocumentsResolverSpy).toHaveBeenCalled()
8187
versionDocumentsResolverSpy.mock.calls.forEach(args => {
82-
expect(args[0]).toBeTruthy()
88+
expect(args[0]).toBeTruthy() // version should not be empty
89+
expect(args[1]).toBeTruthy() // packageId should not be empty
8390
})
8491

8592
// rawDocumentResolver(version, packageId, slug)
93+
// May or may not be called depending on if raw documents are needed
8694
rawDocumentResolverSpy.mock.calls.forEach(args => {
87-
expect(args[0]).toBeTruthy()
95+
expect(args[0]).toBeTruthy() // version should not be empty
96+
expect(args[1]).toBeTruthy() // packageId should not be empty
8897
})
8998
}, 100000)
9099
})

0 commit comments

Comments
 (0)