2021-02-22 - Test asynchronous React state updates - Replace useState - Export Promise created with useEffect
-
Finally a decent test of âwhen there is a previous dialogue ID, there is a menu, when there is not, there is notâ.
-
How do I test the code âwhen the server is sleeping, wait a second and try againâ?
- I see, so instead of using setTimeout raw, you wrap it in a Promise and make a âPromise to be resolved after 1 secondâ.
-
Iâm trying to test the Regroup one, and the problem is that thereâs a lot of drag.
2021-02-25
- Iâm wondering how to test for drags, etc. on Regroup in JestâŚ
- I want to record events and use them for testing, but the problem is that if I record all the mousemove events, the amount of events is too large.
- That kind of event should be recorded only immediately before, and only when the space key is pressed, the previous event is added to the event record.
- This will allow âSurrounding with the long rope toolâ to be expressed with fewer events.
- The problem is that âpressed the space keyâ can be done on a PC, but itâs hard to do on an iPadâŚ
- Do you want to thin it out by hours? Then can you have it recorded by stopping for a moment when you type?
- Sentry with MouseMove thinned out
- I want to record events and use them for testing, but the problem is that if I record all the mousemove events, the amount of events is too large.
- I got the value of the coordinates, but Iâm fireEventing in the test and nothing is happening, itâs hard to track where youâre getting a gripâŚ
- As for testing needs, I donât need to test the âevent arrives when mousedown on canvasâ because it has been tested enough, but I want to test the part after the event arrives.
- It sounds tough, but I managed it.
- Use an object that looks like a ToolEvent, IGNORE the type error, say itâs a ToolEvent, and pass it on.
- Emulate drag and automate âlassoing nothingâ.
- This was a pile of bugs: âit dies when the mouse is downâ, âyou can select it, but lines appear in weird placesâ, and âdragging an enclosed area dies because thereâs nothing to moveâ.
- Iâve reproduced it in a test, and when there was nothing in the enclosed area, I reverted to the mode before it was enclosed, and even if the same bug occurs, the test should tell me next time.
- I want to refactor it because it feels like I was forced to test it and forced to fix it.
- I really wanted to refactor first, but I knew that if I refactored the buggy stuff without writing any tests, it would break a lot, so I held off.
- Itâs not a good design to have the lasso or balloon menu disappear directly in the collision detection between the lasso and the selected object.
2021-02-26
- I checked the screen size before writing the sticky drag test and found that it was 600 x 300, and every time I resized it, it doubled in size, a mysterious phenomenonâŚ
- Simply doing nothing and causing a resize event doubles the canvas size.
- One pixel and one unit on the canvas may be off by a factor of 2 or something.
- For now, it seems that the actual position of a sticky when it is added is determined regardless of its size, so letâs separate it as a separate story and move on.
- Iâm reminded of the Legacy Code Improvement Guide.
- âTo refactor safely you need to test, but to test you need to refactor.â LOL.
- I was able to test the balloon menu by clicking on the sticky, so I thought it was surprisingly easy, but when I tested the drag, the test runner stopped exiting, whyâŚ
- Maybe an infinite loop when Jest strings some kind of object for screen display.
- Itâs not supposed to be a circular referenceâŚ
- I was able to test it to the point where a sticky is selected by lasso selection.
- I was able to eliminate the unpleasant situation of manipulating the menu UI from within the collision detection code, after covering it with tests, happily ever after!
- Coverage is about 39%.
- 46% by adding the tests for selecting multiple items and grouping them together and moving them together.
- Well, letâs add to it, piece by piece.
- When I test with jestâs normal test runner, Iâm so worried about asynchrony, but when I use electron, I write without worrying about it, and it works fine.
- However, testing takes time.
- Hmmm, I clicked on the pen button but it didnât switch to the pen, inexplicableâŚ
- Youâre saying that the pen implementation is grabbing events before where the mouse events are currently being poured, so switching to the pen canât be automated.
- I was able to test the pen drawing, but after drawing with the pen, both the path and the group that encompasses the path appear in the display order⌠this must be a bug that is drawing twiceâŚ
- Coverage is now 51%.
- Letâs do it next week for the issue that may be double drawing.
2021-03-01
- The double drawing was a simple bug that I fixed.
- If this unexpected inconsistency is left unchecked, another problem is likely to occur
- Selecting and ungrouping paths is going to develop into an even stranger situation.
- Paper.js project was created in a test case and accumulated because it was not deleted.
- I removed them all in the afterteach that runs after each test case.
- Iâve been looking at the coverage from the smallest percentage of coverage, but I wonder if itâs possible to order the number of uncovered statements - that would mean the coverage would increase efficiently if you tested it!
- There were none, so Iâll look at them in order of number of rows, or Iâll do the red one with the most rows.
2021-03-02 - Test asynchronous processing in third-party libraries - I wanted to test drawing two passes to investigate the first pass jumps bug, but the canvas redraw in Paper.js was asynchronous.
2021-03-03 - Sentry with MouseMove thinned out - console.log in Safari on iPad
60.32% Statements 1444/2394 41.48% Branches 358/863 59.55% Functions 240/403 60.93% Lines 1421/2332
2021-03-04
- Testing multi-touch operation with touch events
- I havenât been able to reproduce the problem of the two-finger tap becoming a click when released without moving, due to the same âToolEvent not reaching for some reasonâ as before, but I found another bug when I was chasing down the cause of the mysterious error.
- Zoom to zero if two-finger tap is released without moving
- Maybe this is what caused the rare blank slate problem.
- Unexplained Phenomena
- Throwing a mouse event on the canvas is not responsive.
- I threw a touch event and he responded.
- I wrote a test case thinking that touch would respond, but it doesnât.
- Depending on the order in which the test cases were executed, âtouchmove only reacts without touchstart reactingâ occurred.
2021-03-05
-
I notice that there is a warning on elecron side to the effect that âReact status updates are not wrapped in actâ (not relayed to jest side).
-
Elecron does not show where there are unwrapped status updates.
-
Narrow down the range by putting console.log
-
I know where it is, but when you replaced the state update with the mock, shouldnât that have been replaced as well? Thatâs what it looks like.
-
The code to replace useState with mock is working.
-
Then actually that replaced useState is called
-
But it wasnât called at the time of the useState in question.
-
- UseState, maybe replace it with jest.mock.
- Create a mock module that imports React, rewrites it, and re-exports it.
- Instead of calling setState directly, try calling it in fireEvent with onClick that calls it, and if the interpretation is correct, there should be no warning that there is no act
- Try to apply the component separation technique to solve the asynchronous problem by testing separately before and after Promise is used.
- Container/Presentation separation
- Designing it that way makes it easier to test.
- On the other hand, when âadding tests to something that doesnât yet have test code,â we want to cover it with tests and then refactor it, rather than refactor it and then test it.
- UseState, maybe replace it with jest.mock.
-
I wrapped it honestly because I was warned to âwrap it in ACTâ in the first place, but you donât understand what is done when you wrap itâŚ
- react-dom/test-utils
- react-testing-library
2021-03-08 - test-utils act do?
-
useState, maybe we can replace it with jest.mock
Do not import @jest/globals outside of the Jest test environment
- Iâm not quite sure why Iâm getting this error.
- requestAnimationFrame + jest-electron = unstable behavoir
2021-03-09~2021-03-12
This page is auto-translated from /nishio/JestăĄă˘ using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. Iâm very happy to spread my thought to non-Japanese readers.