Skip to content

Conversation

@julieg18
Copy link
Contributor

@julieg18 julieg18 commented Sep 26, 2022

Followup to #2436 comment

@julieg18 julieg18 self-assigned this Sep 26, 2022
@julieg18 julieg18 changed the title Add tests for table depth configuration Add tests for column depth configuration Sep 26, 2022
@julieg18 julieg18 marked this pull request as ready for review September 26, 2022 17:03
@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 3e27203 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (85% is the threshold).

This pull request will bring the total coverage in the repository to 97.0% (0.0% change).

View more on Code Climate.

@julieg18 julieg18 merged commit bd1fbc5 into main Sep 26, 2022
@julieg18 julieg18 deleted the add-tests-for-table-depth-config branch September 26, 2022 23:27
jest.mock('../../../vscode/config')

const mockedGetConfigValue = jest.mocked(getConfigValue)
mockedGetConfigValue.mockImplementation(() => 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[I] The usual pattern is to use beforeEach with resetAllMocks to keep tests independent

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

I thin you could use mockReturnValueOnce instead of mockImplementation as well. Final code would probably be

beforeEach(() => {
  jest.resetAllMocks()
  mockedGetConfigValue.mockReturnValueOnce(5)
})

for this particular file as we are not varying the option.

workspace.getConfiguration().get(key, '') as unknown as T
export const getConfigValue = <T = string, D = string>(
key: ConfigKey,
defaultValue?: D | T
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this translates to defaultValue?: string ... 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be

export const getConfigValue = <T = string>(
  key: ConfigKey,
  defaultValue: T | undefined
): T =>
  workspace.getConfiguration().get(key, defaultValue ?? '') as unknown as T

jest.mock('../../vscode/config')

const mockedGetConfigValue = jest.mocked(getConfigValue)
mockedGetConfigValue.mockImplementation(() => 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[I] Can also use a beforeEach this time I would but the mockReturnValueOnce calls inside of the tests as the value is being varied throughout the file

Copy link
Contributor

@mattseddon mattseddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was meant to be an approval

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants