image
image copied to clipboard
Expose $Img for external Testing
We have a component that uses direct access to $img.getImage to generate image URLs. To test this component we write simple jest snapshot tests. Unfortunately I have not been able to inject $img into our component to run tests without mocks. This is our current approach:
describe('OurImageComponent', () => {
function buildWrapper () {
return mount(
OurImageComponent,
{
propsData: { // ...
},
mocks: {
$img: {
getImage (url, options) { // some mock implementation
},
},
},
( Inspired by https://github.com/nuxt/image/blob/main/test/unit/utils/mount.ts )
This works well but with mocking the actual call we generate unclean snapshot files and not really exact URLs.
Is there a way to create an instance of $Img manually in a test environment or would it be an option to expose the
createImage function so one could create an instance manually?