You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Hard to unit test in isolation
Describe the solution you'd like
Ability to mock functions and get proper type for example
constdouble: (n: number): number =>n*2;constdoubleMock: ((n: number)=>number)&jest.Mock=mockIt(double);// such that doubleMock extends the jest.mock type so this 👇 worksdoubleMock.mockReturnValue(12);
Note: Should work for mocking modules, classes and individual functions.
Describe alternatives you've considered
Not having to do (scale.scale as jest.Mock) to mock the functions
describe('getPosition',()=>{// @ts-ignoreconstscale: Scale={scale: jest.fn(),};beforeEach(()=>{(scale.scaleasjest.Mock).mockClear();});it('should return value from scale',()=>{(scale.scaleasjest.Mock).mockReturnValue(20);constresult=getPosition(10,scale);expect(result).toBe(20);});it('should call scale with correct args',()=>{getPosition(10,scale);expect(scale.scale).toBeCalledWith(10);});});
Unit test coverage is very good but I feel like the current tests don’t fully cover each scenario and enforce bug fixes. Every bug that is fixed, in my mind, should have a unit test that enforces that use case.
There is also a lack of component test coverage.
There is a lot of boilerplate code that is used to make assertions for just one use case then repeated for another. I think this could be DRY’d up but creating helper functions as well as default configurations constants that are then changed to make a given assertion. This can then be enhanced using property based testing via jsverify or others.
In my last job, I had a difficult time testing code in typescript as the assertions require each type to be fully built out or it will complain. Using ts-ignore is a useful workaround but employing helper functions to make partial assertions would be very beneficial. This is most common with mocked functions. I don’t care about the type I just want to assert that the function is called with the given arguments. Mocks are a MUST in jest testing and they are seldom used requiring a full build out of required parameters to make a given assertion.
Mocking canvas
Mocking the canvas element in unit tests is a good way to make assertions on the api level but it’s hard to capture all that a visual testing system would.
The text was updated successfully, but these errors were encountered:
Yeah, I think all the testing XxxMock additions address the majority of this issue. The mockIt function may be helpful but that's easy to add if we see need.
Is your feature request related to a problem? Please describe.
Hard to unit test in isolation
Describe the solution you'd like
Ability to mock functions and get proper type for example
Describe alternatives you've considered
Not having to do
(scale.scale as jest.Mock)
to mock the functionsUnit test coverage is very good but I feel like the current tests don’t fully cover each scenario and enforce bug fixes. Every bug that is fixed, in my mind, should have a unit test that enforces that use case.
There is also a lack of component test coverage.
There is a lot of boilerplate code that is used to make assertions for just one use case then repeated for another. I think this could be DRY’d up but creating helper functions as well as default configurations constants that are then changed to make a given assertion. This can then be enhanced using property based testing via jsverify or others.
In my last job, I had a difficult time testing code in typescript as the assertions require each type to be fully built out or it will complain. Using ts-ignore is a useful workaround but employing helper functions to make partial assertions would be very beneficial. This is most common with mocked functions. I don’t care about the type I just want to assert that the function is called with the given arguments. Mocks are a MUST in jest testing and they are seldom used requiring a full build out of required parameters to make a given assertion.
Mocking canvas
Mocking the canvas element in unit tests is a good way to make assertions on the api level but it’s hard to capture all that a visual testing system would.
The text was updated successfully, but these errors were encountered: