Skip to content

Commit

Permalink
Tidy up test file
Browse files Browse the repository at this point in the history
  • Loading branch information
anushkafka committed Sep 4, 2024
1 parent 0f1f71e commit c23b556
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/zcli-apps/src/lib/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,33 @@ describe('package', () => {
describe('validatePkg', () => {
test
.stub(fs, 'pathExistsSync', () => true)
.stub(fs, 'readFile', () => Promise.resolve('file content'))
.stub(request, 'requestAPI', () => Promise.resolve({ status: 200 }))
.it('should return true if package is valid', async () => {
expect(await validatePkg('./app-path')).to.equal(true)
})

test
.stub(fs, 'pathExistsSync', () => true)
.stub(fs, 'readFile', () => Promise.resolve('file content'))
.stub(request, 'requestAPI', () => Promise.resolve({ status: 400, data: { description: 'invalid location' } }))
.do(async () => {
await validatePkg('./app-path')
.it('should throw if package has validation errors', async () => {
try {
await validatePkg('./app-path')
} catch (error: any) {

Check warning on line 23 in packages/zcli-apps/src/lib/package.test.ts

View workflow job for this annotation

GitHub Actions / build-and-check (ubuntu-latest, 18.x)

Unexpected any. Specify a different type

Check warning on line 23 in packages/zcli-apps/src/lib/package.test.ts

View workflow job for this annotation

GitHub Actions / build-and-check (macos-latest, 18.x)

Unexpected any. Specify a different type
expect(error.message).to.equal('invalid location')
}
})
.catch('invalid location')
.it('should throw if package has validation errors')

test
.stub(fs, 'pathExistsSync', () => false)
.do(async () => {
await validatePkg('./bad-path')
.stub(fs, 'readFile', () => Promise.reject(new Error('Package not found at ./bad-path')))
.it('should throw if app path is invalid', async () => {
try {
await validatePkg('./bad-path')
} catch (error: any) {

Check warning on line 34 in packages/zcli-apps/src/lib/package.test.ts

View workflow job for this annotation

GitHub Actions / build-and-check (ubuntu-latest, 18.x)

Unexpected any. Specify a different type

Check warning on line 34 in packages/zcli-apps/src/lib/package.test.ts

View workflow job for this annotation

GitHub Actions / build-and-check (macos-latest, 18.x)

Unexpected any. Specify a different type
expect(error.message).to.equal('Package not found at ./bad-path')
}
})
.catch('Package not found at ./bad-path')
.it('should throw if app path is invalid')
})
})

0 comments on commit c23b556

Please sign in to comment.