user762579
user762579

Reputation:

Vue.js unit test testing a component , got props type error

I am trying to test an audio player ( start , pause, stop , mute, position, download events)

export default {
  name: "audioPlayer",
  props: {
    file: {
      type: Object,
      default: null
    },
    autoPlay: {
      type: Boolean,
      default: false
    },

In my test specs, I set the file props as follwoing

  const file = new File(["../../src/assets/audio/ultimo_desejo.mp3"], "ultimo_desejo", { type: "audio/mp3"});
  const ended = jest.fn();

But when I run the test , I get an erro :

console.error node_modules/vue/dist/vue.runtime.common.js:589 [Vue warn]: Invalid prop: type check failed for prop "file". Expected Object, got File.

found in

---> <AudioPlayer>
       <Root>

How should I set my file property ?

thanks for feedback

Upvotes: 0

Views: 1365

Answers (1)

tony19
tony19

Reputation: 138196

Change the type field of the file prop to File:

props: {
  file: {
    type: File,
    default: null
  },
}

Then, you could pass a new File in the file prop:

it('takes a file prop', () => {
  const file = new File(['foo'], 'foo.txt');
  const wrapper = shallowMount(MyFoo, {
    propsData: { file }
  });
  expect(wrapper.vm.file).toBeTruthy();
})

demo

Upvotes: 1

Related Questions