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()


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.

Related Posts

Want to learn about the types of products we build?

Check out our projects

Like what you're seeing? Let's keep in touch.

Subscribe to Our Newsletter