Skip to content

Reintroduce / undeprecate method overriding #1809

@movitto

Description

@movitto

Feature Description

Thank you for the great library. Previous versions facilitated overriding methods via the methods parameter to mount and/or the setMethods call. Please consider reintroducing this feature for the reasons below.

Problem

Lets say I have a vue component that uses the vue-resource library like so:

{
  name : 'DemoComponent',

  data : function(){
     return {foobar : ''}
  },

  methods : {
     get_data : function(){
        this.$http.get("https://foo.bar")
                       .then(function(response){
                           this.foobar = response.body;
                        }.bind(this))
     }
  },

  created : function(){
     this.get_data()
  }
}

Best practices is to stub out network / http calls in test suites. So as not to couple the test suite to implementation details, previously one could override the get_data method like so:

mount(DemoComponent, {
  methods : {
    get_data : function(){
       this.foobar = '{"foo" : "bar"}'
    }
  }
})

Everyone is happy. The test suite doesn't invoke a network request, nor is it coupled to the implementation details of how the data is retrieved.

The problem is w/ version 1.x of this library the methods parameter to mount was deprecated and it was removed all together in version 2.x.

We are requesting that this functionality is readded to this library for the above reason and so that the workaround described below is not needed.

Expected behaviour

The mount method should accept and use the methods param and the setMethods call should be added to the Wrapper class.

Alternatives

One could use a mixin to override the method:

const override = {
  methods : {
    get_data : function(){
       this.foobar = {foo : 'bar'}
    }
  }
}

mount(DemoComponent, {mixins : [override]})

This achieves the same effect, but is a roundabout way to achieve the result.

Of course in the above example, we could stub/override the $http.get method, but this best practices is to test the interface and expected results and not the implementation


Thank you for considering this feature and thank you again for the great library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions