Spy or stub methods before mount
See original GitHub issueI’ve got some methods that are called on created, mounted events. I can’t seem to be able to spy on them properly (or make stubs).
What I tried so far is, is spying on methods of pre mounted element and then checking if the spy was called. This doesn’t work even when the actual method was called (tested by adding simple consolel.og)
Example:
it('calls myMethod when mounted', () => {
const spy = sinon.spy(myComponent.methods, 'myMethod')
const wrapper = mount(myComponent, { propsData, store })
expect(spy.called).to.be.true // AssertionError: expected false to be true
})
Using Karma, Mocha and Sinon. I hope this is enough info and appropriate place to ask this.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Stubs, Spies, and Clocks | Cypress Documentation
The same concept applies to mounting a component with cy.mount() . We bind before any timers from your code can be invoked. Restore...
Read more >java - Mockito - @Spy vs @Mock - Stack Overflow
A spy in mockito is a partial mock in other mocking frameworks (part of the object ... If you want to change and...
Read more >Best Practices for Spies, Stubs and Mocks in Sinon.js
The assertion within the stub ensures the value is set correctly before the stubbed function is called. Remember to also include a sinon.assert....
Read more >Stubs, Spies and Mocks in JavaScript · Harry's Blog
Spy on functions and see when or if they are called. Pros: Check if a method has been called with certain variables; Check...
Read more >Mock vs Stub vs Spy - Javatpoint
In Mockito, spy() method is used for creating spy objects. It allows us to call the normal methods of the real object. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This test works for me -
There must be something else going on here.
Can you link me to the full repo?
Edd, you’re a legend man‼️
Thanks so much, now the joy of coding is back 🕺