Make sure named spies are declared only in before/after/it jasmine blocks.
Spies created in global scope or directly in define blocks don't
get automatically reset/cleaned by the jasmine teardown process, making it possible
to get false positives when using toHaveBeenCalled()
/ toHaveBeenCalledWith()
.
This rule checks for the following methods: spyOn
, jasmine.createSpy()
, jasmine.createSpyObj()
.
The following are considered warnings:
// myFile.js
var mySharedSpy = jasmine.createSpy()
spyOn(someObj, "someMethod")
describe(function () {
var mySharedSpy = jasmine.createSpy()
spyOn(someObj, "someMethod")
})
The following patterns are not warnings:
beforeEach(function () {
var mySpy = jasmine.createSpy()
spyOn(someObj, "someMethod")
})
beforeAll(function () {
var mySpy = jasmine.createSpy()
spyOn(someObj, "someMethod")
})
afterEach(function () {
var mySpy = jasmine.createSpy()
spyOn(someObj, "someMethod")
})
afterAll(function () {
var mySpy = jasmine.createSpy()
spyOn(someObj, "someMethod")
})
it(function () {
var mySpy = jasmine.createSpy()
spyOn(someObj, "someMethod")
})