Here is how my test looks
import { SlugGeneratorAdapter } from './slug-generator-adapter'
import slugify from 'slugify'
describe('SlugGenerator Adapter', () => {
test('Should call the slug generator with the correct parameters.', () => {
const target = new SlugGeneratorAdapter()
const slugifySpy = jest.fn(slugify)
target.generate('any text')
expect(slugifySpy).toHaveBeenCalledWith('any text')
}
)
})
Another relevant class I have is as follows:
import slugify from 'slugify'
import { SlugGenerator } from '../../data/protocols/slug-generator'
export class SlugGeneratorAdapter implements SlugGenerator {
generate (param: string): string {
slugify(param)
return 'any_value'
}
}
I am struggling with implementing this test due to my limited knowledge of Jest. The failing issue seems to be related to slugify never being called (as far as I can tell). For those unfamiliar, slugify is a function that adds dashes to a string.
As an example, you can see how it works below:
import slugify from 'slugify'
slugify('any text more text') it returns // any-text-more-text