question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: ComponentStub helper

See original GitHub issue

I’ve added this helper in my own codebase, but if useful to this project I’m happy to submit a PR. The code is below.

export function ComponentStub(name) {
  this.rendered = false;
  this.name = name;
  this.render = (h) => {
    this.rendered = true;
    return h();
  };
}

export default function componentStub(component, ...components) {
  const stubs = {};
  components.forEach((name) => {
    stubs[name] = new ComponentStub(name);
  });
  component.components = { ...component.components, ...stubs };
}

Usage is simple:

import { shallow } from 'avoriaz';
import { componentStub } from '@/lib/avoriaz';
import Component from './Component';

componentStub(Component, 'router-link', 'router-view');

As a small bonus it provides stub telemetry for the render function.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
eddyerburghcommented, Jul 19, 2017

@ndabAP no I’ll continue to support and evolve it, but most of my time will be spent on vue-test-utils

1reaction
eddyerburghcommented, Jul 15, 2017

@chrisnicola yes good idea on the array for options.stub. I’ll add it to the todo

Read more comments on GitHub >

github_iconTop Results From Across the Web

can not stub/mock helper methods #396 - ruby-grape ... - GitHub
for instance, I have a helper method named current_user, it returns the obvious value. I want to test an api request, once when...
Read more >
How to stub a Rails helper/module method in Rspec 3 feature ...
I've seen this done using the older should_receive syntax, but I can't figure out how to stub a Rails module method in Rspec...
Read more >
Using RSpec Stub and Mock | Cloudbees Blog
Stubbing and Mocking makes your component examples independent of other components. You can stub methods on objects to let them return ...
Read more >
How to test software: mocking, stubbing, and contract testing
A great application of mocks and stubs in a unit/component test is when your implementation interacts with another method or class. You can...
Read more >
Build a Mocking Framework with the Stub API
createStub () method. This feature is intended for advanced Apex developers. Using it requires a thorough understanding of unit testing and mocking frameworks....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found