Skip to content

Commit

Permalink
refactor: remove fragile tests that test implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
milenacrios committed Mar 11, 2024
1 parent defdb68 commit 4ac7b7c
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/async-tokenize/async-tokenize.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { fireEvent, waitFor } from '@testing-library/dom'

import { AsyncTokenize } from './async-tokenize'
import * as utilsValues from 'src/common/utils/form-values/form-values'
import * as utilsElements from 'src/common/utils/form-elements/form-elements'
import {
configureFormSubmissionMock,
formElementsMock,
formValuesMock,
malgaConfigurations,
} from 'tests/mocks/common-configurations'
import { generateForm } from 'tests/mocks/form-dom'
Expand Down Expand Up @@ -117,40 +114,6 @@ describe('async-tokenize', () => {
expect(inputs.length).toBe(1)
})
})
test('should be possible for handle to call the getFormElements, getFormValues, Tokenization, removeFormElements and createFormElements functions passing the elements correctly', async () => {
configureFormSubmissionMock()

generateForm(onSubmit)

const malga = new Malga(malgaConfigurations(false))

const asyncTokenizeObject = new AsyncTokenize(malga, formElementsMock)

const getFormElementsSpy = vi.spyOn(utilsElements, 'getFormElements')
const getFormValuesSpy = vi.spyOn(utilsValues, 'getFormValues')
const tokenizationSpy = vi.spyOn(malga, 'tokenization')
const removeFormElementsSpy = vi.spyOn(utilsElements, 'removeFormElements')
const createFormElementSpy = vi.spyOn(utilsElements, 'createFormElement')

asyncTokenizeObject.handle()

const form = document.querySelector('form')
fireEvent.submit(form!)

await waitFor(() => {
const tokenIdInput = document.querySelector<HTMLInputElement>(
'input[name="tokenId"]',
)
expect(getFormElementsSpy).toHaveBeenCalledWith(formElementsMock)
expect(getFormValuesSpy).toHaveBeenCalledWith(formElementsMock)
expect(tokenizationSpy).toHaveBeenCalledWith(formValuesMock)
expect(removeFormElementsSpy).toHaveBeenCalledWith(formElementsMock)
expect(createFormElementSpy).toHaveBeenCalledWith(
tokenIdInput?.name,
tokenIdInput?.value,
)
})
})

test('should be possible to return an error if empty apiKey and clientId are sent to the Malga constructor', async () => {
configureFormSubmissionMock()
Expand Down

0 comments on commit 4ac7b7c

Please sign in to comment.