Skip to content

Expected Behavior of Error Propogation #147

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

Closed
Austio opened this issue Nov 3, 2017 · 6 comments · Fixed by #154
Closed

Expected Behavior of Error Propogation #147

Austio opened this issue Nov 3, 2017 · 6 comments · Fixed by #154

Comments

@Austio
Copy link
Contributor

Austio commented Nov 3, 2017

Hey sorry for the multiple issues but saw this while driving out a test.

This may be more of a discussion, but what is the intended behavior of error propogation in vue-test-utils? I created an example below but what i'm seeing in production is a mounted function in throwing an error due to some bad assumptions and that causes a white screen. In my test when i reproduce by throwing an error in the mounted function I see the error in the console but I am not able to access it in vue-test-utils, i've tried numerous 'mocha' like ways to get the error to surface but was unable to.

Any thoughts on how to get access to thrown errors?

Here is a repo with reproduction.
https://github.com/Austio/vue-test-utils-mocha-webpack-example/pull/1/files

@Austio
Copy link
Contributor Author

Austio commented Nov 3, 2017

I think that the throw('error') should either be accessible on the wrapper or propagate up. See repo for above for the full example.

mounted() {
  console.error('throwing an error');
  throw('Error');
}

screenshot from 2017-11-03 10-54-11

@Austio
Copy link
Contributor Author

Austio commented Nov 3, 2017

found a way to test the error, does not seem ideal but would work

describe('when it errors', function() {
    let errorConsole;
    beforeEach(() => {
      errorConsole = sinon.stub(console, 'error');
    });

    afterEach(() => {
      errorConsole.restore();
    });

    it('does not error when the header is initialized with null', function() {
      mount(LoggedIn, {
        localVue,
        attachToDocument: true,
        store,
      });

      expect(errorConsole.called, `Console Error: ${errorConsole.args[0]}`).not
        .to.be.true;
    });``

@Austio
Copy link
Contributor Author

Austio commented Nov 5, 2017

Had an additional thought on this. Could we take advantage of the errorHandler?

function globalHandleError (err, vm, info) {
  if (config.errorHandler) {
    try {
      return config.errorHandler.call(null, err, vm, info)
    } catch (e) {
      logError(e, null, 'config.errorHandler')
    }
  }
  logError(err, vm, info)
}

@eddyerburgh
Copy link
Member

Hi @Austio.

You're right, thrown errors should make a test fail. Are you able to make a PR to improve error propagation?

@Austio
Copy link
Contributor Author

Austio commented Nov 5, 2017

@eddyerburgh #154 Proof of concept for idea to handle. Please let me know what you think and will finish out if this is good direction to go.

@eddyerburgh
Copy link
Member

Looks perfect Austio, I've left some feedback on style issues, ready to merge when they're fixed

eddyerburgh pushed a commit that referenced this issue Nov 9, 2017
)

* Propogate thrown errors by configuring error handler and attaching in mount function resolves #147

* set errorHandler to be a default export and set Vue.config.errorHandler = errorHandler in mount

* Add test for create-local-vue error handler being defined and configure that in create local vue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants