Open Valdermeyder opened 7 years ago
Hello! I have the same issue:
describe("someTest", ()=>{
it("test1", ()=>{
createSpy();
})
it("test2", ()=>{
createSpy();
})
})
function createSpy(){
return jasmine.createSpy('validate() spy')
}
Causes a
warning Spy declared outside of before/after/it block jasmine/no-unsafe-spy
Warning.
I'm also faced the same problem when I tried to declare helper function which will return a spy. I'm ended up disabling this rule for now.
Same here. Any ideas on a possible fix for this rule?
I just disabled because couldn't figure out any other way to fix this issue at the moment.
Edit: just found out that apparently you can retrieve the beforeEach function itself.
const initSpies = () => beforeEach(() => ({
params: {},
getData: jasmine.createSpy('getData'),
getValidations: jasmine.createSpy('getValidations'),
}));
describe('suite', () => {
let params;
let getData;
let getValidations;
initSpies();
});
Do you want to request a feature or report a bug? I suppose it is rather new feature than bug
What is the current behavior?
For code above next warning will be shown
warning Spy declared outside of before/after/it block jasmine/no-unsafe-spy
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior? Warning should not be shown if function
initSpies
is called only from before/after/it blockPlease mention your node.js, eslint-plugin-jasmine and operating system version. node.js v7.2.1 eslint-plugin-jasmine v2.2.0