Skip to content

Commit

Permalink
add error handling testa
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-siek committed Feb 11, 2025
1 parent e09f633 commit 827354c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,37 @@ describe('linter', () => {
)
}
})

it('should handle invalid linter config errors from server', async () => {
const files = ['test.js']
const invalidLinterConfig = {
rules: {
'invalid-rule': 'invalid-value'
}
}

// Setup file read
readFileStub.withArgs('test.js', 'utf8').returns('const x = 1;')

// Setup Nock to simulate 400 response with config validation error
const scope = nock(axeLinterUrl)
.post('/lint-source', {
source: 'const x = 1;',
filename: 'test.js',
config: invalidLinterConfig
})
.matchHeader('content-type', 'application/json')
.matchHeader('authorization', apiKey)
.replyWithError('Invalid config')

try {
await lintFiles(files, apiKey, axeLinterUrl, invalidLinterConfig)
assert.fail('Should have thrown an error')
} catch (error) {
assert.instanceOf(error, Error)
assert.include(error.message, 'Invalid config')
assert.isTrue(scope.isDone(), 'API request should be made')
}
})
})
})

0 comments on commit 827354c

Please sign in to comment.