New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: attributes.item is not a function #1886
Comments
I have tried to run a similar test and it works both import { shallowMount } from '@vue/test-utils';
import MyImage from '@/components/MyImage';
describe('MyImage.vue', () => {
it('calls an `imgLoadCallback()`', async () => {
const wrapper = shallowMount(MyImage);
const spy = jest.spyOn(wrapper.vm, 'imgLoadCallback');
const img = wrapper.find('img');
await img.trigger('load');
expect(spy).toHaveBeenCalled();
});
}); <template>
<img :src="logo" @load="imgLoadCallback()" />
</template>
<script>
import logo from '../assets/logo.png';
export default {
name: 'MyImage',
data() {
return {
logo,
};
},
methods: {
imgLoadCallback() {
console.log("I'm loaded!");
},
},
};
</script> |
Subject of the issueI have a simple component with a form and a button element. When I execute a test with the following code:
I get the following error:
Project ConfigurationNode version: v14.15.4 Vue-test-utils version: 1.0.3 Using Vue 2 + Typescript Steps to reproduceMy Component
My test
My jest.config.js
The error is being triggered from the I can confirm that replacing const att = attributes.item(i) to const att = attributes[i] worked. Were you able to find any workaround @lukaszkups ? |
@nikhilgosavi007 unfortunately not, sorry, I've just abandoned testing that particular use case and switched to different topics to be honest 🥲 |
@lukaszkups Try using |
Unfortunately I'm not allowed to change this dependency, but thank you for the tip with available solution 🙌 |
@lukaszkups How did you end up fixing it? |
I didn't, just skipped testing this particular piece of code for the time (and it still is not tested) - I've added a possible suggestion how to solve it (by modifying |
This is the root cause: capricorn86/happy-dom#308. Not fixed yet, but happy-dom has been having a lot of activity lately so maybe soon... |
capricorn86/happy-dom#308 is fixed now in 7.6.0 |
Subject of the issue
I have a component that contains an image (
<img />
) element.When I execute a test with the following code:
Steps to reproduce
Create any Vue component that contains
img
element inside with binded@load="onImgLoad"
method forimg
DOM element.Create following test:
Expected behaviour
Test should pass just fine, load event should be triggered 1 time.
Actual behaviour
Test fails and throws an error:
TypeError: attributes.item is not a function
It also fails for other DOM elements (selected via
wrapper.find()
), when I try to use.trigger
methods with other events on them.Node version: v14.15.4
Vue-test-utils version:
1.0.0-beta.31
Using Vue 2 + Typescript
Possible Solution
I've updated the
vue-test-utils.js
file inside mynode_modules
folder (file url in the github repo: https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/wrapper.js )In this method definition:
I've replaced
const att = attributes.item(i)
toconst att = attributes[i]
and test started passing just fine.The text was updated successfully, but these errors were encountered: