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.

Add a testing guide

See original GitHub issue

So, i have been trying to find examples of unit tests and the lack of information i find disturbing…

For example, a couple of versions ago, functions and objects like ready and watch would show up green in the code coverage, and idem for the command-line coverage… now i have updated some projects to make use of mocha and suddenly my coverage dropped significantly! And further more i cannot find how to properly test ready() and watch, even the official examples do not include unit tests! I have tried asking on gitter as well, but it seems unit-testing isn’t all that popular… But i really need it, since the company i work for considers Vue for a new big front-end, i need to show them that Vue is up to par with the other frameworks out there.

What i would really really need is a guide on how to properly test a single file component. For example, ready() is called by Vue itself, so should i mock this and spy on it to see if its called?! That seems like such a hassle and i would like to have the behavior that was before where it would just show up as covered… cause if there is a error in ready, stuff would already break, right?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ameesterscommented, Apr 13, 2016

those slides are very valuable thank you, about that ready thing, have my component mounted on a dummy parent like so:

const vm = new Vue({
    template: '<div><app></app></div>',
    components: { App }
  }).$mount()

As per the docs… Now this is what my ready function looks like:

  ready () {
    // initial data requests:
    this.getSyncData()
    this.getImportData()
    this.getImportInformation()

    let _pollForChanges = () => {
      setTimeout(() => {
        this.checkForChanges()
        // call self:
        _pollForChanges()
      }, settings.defaultInterval)
    }

    // kick-off for the recursive function
    _pollForChanges()
  }

And this is the report output: ready_in_red

Now how do i make sure ready would pass? i have tried a bunch of things now and i am lost. Cause the funny thing is, this was green before i updated it, with all test passing…

Now, after the upgrade i have run my tests again, still they all pass, but my coverage went way down. Maybe some changes were implemented that made it more strict about what code it considered tested?

1reaction
yyx990803commented, Apr 13, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a test - The Go Programming Language
Implement test functions in the same package as the code you're testing. Create two test functions to test the greetings.Hello function. Test function...
Read more >
How to Write Test Cases: The Ultimate Guide with Examples
So, it is always better to add a timestamp with the tester's name in the testing comments so that a test result (pass...
Read more >
The Ultimate Guide to Software Testing
This is the 'How' section of our 4 part Ultimate Guide to Software Testing. ... Maintaining and adding to an internal testing team...
Read more >
Unit Testing Tutorial: 6 Best Practices to Get Up To Speed
1. Arrange, Act, Assert · 2. One Assert Per Test Method · 3. Avoid Test Interdependence · 4. Keep It Short, Sweet, and...
Read more >
Beginner's guide to writing end-to-end tests - GitLab Docs
Before you write a test · Determine if end-to-end tests are needed · Identify the DevOps stage · Create a skeleton test ·...
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