Using Jest mock functions changes method syntax inspection

Hi,

I have the following problem, but maybe I miss something here:

If I am using jest mock functions in my tests the tested method in source code coloring also changing. I think the mocked function shown as instance field even though I am using it as a method. So I think Webstorm no longer realize that this is a method.

Should I set up something to fix this or this is acceptable?

 

Thanks for your help in advance!

 

6 comments
Comment actions Permalink

Could you share code snippets/screenshots that illustrate the issue?

0
Comment actions Permalink

Hi Elena,

What I found out the problem is that when I assigne the jest.fn() to the instansce it will become this. If I use spyOn and mocking the method that way it will be OK.

But Webstorm why not realize it as a method when I am calling it?...

I think what I would like is a scope which is avoiding test files.

0
Comment actions Permalink

Please could you share complete code snippets as text/files?

0
Comment actions Permalink

Sorry I wasn't able to share text file here.

foo-a.js

class A {
bar() {
console.log('Hello');
}
}

module.exports = A;

 

foo-b.js

class B {
constructor(a) {
this.a = a;
}

baz() {
this.a.bar();
}
}

module.exports = B;

 

foo.test.js

describe('use mock', () => {
let b;

beforeEach(async(done) => {
const A = require('./foo-a');
const a = new A;
const B = require('./foo-b');
b = new B(a);
done();
});

it('should mock bar', async(done) => {
b.a.bar = jest.fn();
b.baz();

expect(b.a.bar).toHaveBeenCalled();

done();
});
});

0
Comment actions Permalink

thank you! Please vote for https://youtrack.jetbrains.com/issue/WEB-44797 to be notified on any progress with it

0
Comment actions Permalink

Thanks Elena!

0

Please sign in to leave a comment.