14 July 2017
TIL: How to Correctly Use a Jasmine Spy
At Gaslight we are all about continuously growing and learning, so we’re starting a “Today I Learned Series”! Stay tuned for more tidbits!
I often find myself stumped when trying to use spies in a JavaScript test… Until Today.
TIL: How to correctly use a Jasmine Spy:
Foo = require('foo')
describe 'Foo'
describe 'bar'
it 'does a thing'
spyOn(Foo, 'bar')
foo = new Foo()
expect(foo.bar).toHaveBeenCalled()
Run into no method error
? Try spyOn(Foo.prototype, 'bar')
.
- Jasmine is a popular JavaScript testing framework
- Spies are a type of test double that allow you to stub functions and track the function call, and it’s arguments
For more information on Jasmine Spies, visit their documentation.
Heads up! This article may make reference to the Gaslight team—that's still us! We go by Launch Scout now, this article was just written before we re-introduced ourselves. Find out more here.