Skip to content

Required Properties Should Throw An Exception When Component Is Initialised Without Them #704

Open
@fungus1487

Description

@fungus1487

What problem does this feature solve?

Currently it is impossible to unit test correct initialisation of our components.Testing positive cases such as "does a property exist" after init works well, however with a large library of components we also need to consider negative test cases such as "don't allow component to initialise if required properties are missing" An example is shown below:

describe('Input', () => {
  it('fail initialization with no value', () => {
    const vm = mount(Input, {
      propsData: {},
    });

    // expecting above to fail due to required prop 'value'
  });
});

Currently Vue will report to the console with a warning but really this needs to be caught automatically with larger projects as manually testing and checking coverage simply by using the console is inadequate.

The ability to even configure this at a project level would be useful e.g. throwOnMissingRequiredProps: true

What does the proposed API look like?

For backwards compatibility introduce a runtime variable which would consider whether to throw or report missing required component properties to the console.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions