Skip to content

Commit

Permalink
Chore: Update tests and restore all mocks after each test
Browse files Browse the repository at this point in the history
  • Loading branch information
WilsonZiweiWang committed Nov 20, 2023
1 parent 9bdf5b7 commit 2ade6d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions server/src/__tests__/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ describe('On Completion', () => {
bitBakeDocScanner.clearScannedDocs()
})

afterEach(() => {
jest.restoreAllMocks()
})

it('expects reserved variables, keywords and snippets in completion item lists', async () => {
// nothing is analyzed yet, and docs are not scanned. Only the static and fallback completion items are provided
const result = onCompletionHandler({
Expand Down
11 changes: 7 additions & 4 deletions server/src/__tests__/definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import { analyzer } from '../tree-sitter/analyzer'
import { generateParser } from '../tree-sitter/parser'
import { onDefinitionHandler } from '../connectionHandlers/onDefinition'
import { FIXTURE_DOCUMENT } from './fixtures/fixtures'
import contextHandler from '../ContextHandler'
import { type Location } from 'vscode-languageserver'

import { definitionProvider } from '../DefinitionProvider'
// TODO: Current implementation of the definitionProvider needs to be improved, this test suite should be modified accordingly after
const mockDefinition = (path: string | undefined): void => {
if (path !== undefined) {
const location: Location = { uri: 'file://' + path, range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } } }

jest.spyOn(contextHandler, 'getDefinitionForDirectives').mockReturnValueOnce(location)
jest.spyOn(definitionProvider, 'createDefinitionForKeyword').mockReturnValue(location)
} else {
jest.spyOn(contextHandler, 'getDefinitionForDirectives').mockReturnValueOnce([])
jest.spyOn(definitionProvider, 'createDefinitionForKeyword').mockReturnValue([])
}
}

Expand All @@ -35,6 +34,10 @@ describe('on definition', () => {
analyzer.resetAnalyzedDocuments()
})

afterEach(() => {
jest.resetAllMocks()
})

it('provides definition to directive statement', async () => {
await analyzer.analyze({
uri: DUMMY_URI,
Expand Down

0 comments on commit 2ade6d7

Please sign in to comment.