简体   繁体   中英

how console.log in tests

I have such test and i want see console.log in my terminal. how i can got it? for example console.log(rafSpy). Сan you do so at all?

it("should not render coin if move time ended", () => {
            const rafSpy = jest.spyOn(window, "requestAnimationFrame");
            console.log(rafSpy)
            let rafCb;
            rafSpy.mockImplementation(cb => rafCb = cb);
            const perfSpy = jest.spyOn(performance, "now");
            perfSpy.mockReturnValue(0);

            const subject = mount(<CoinsAndStars stars={true} coins={true} DeviceSupport={DeviceSupport} />);
            ctxMock.ellipse = jest.fn();
            subject.instance().coins[0].moveTime = 2;
            subject.instance().coins[0].lifeTime = 1.5;
            const visibleCoinCount = COIN_COUNT - 1;
            const ellipseDrawCountInOneFrameRender =
                ((COIN_WIDTH * 2) / EDGE_SEGMENT_STEP + 1)
                * visibleCoinCount
                + visibleCoinCount;
            // 1.5sec of lifet will be increased by 0.6ms
            rafCb(600);
            expect(subject.instance().coins[0].lifeTime).toBeGreaterThan(2);
            expect(ctxMock.ellipse).toHaveBeenCalledTimes(ellipseDrawCountInOneFrameRender);
            rafSpy.mockRestore();
            perfSpy.mockRestore();
        });

What you are attempting to accomplish may need a work-around seeing as how the Web API, Console , as used in your code, may only serve as a functional interface from Browser-to-Browser.

One suggestion that I have is to use an Interactive Developer Environment(IDE) to find a similar work-flow. An IDE like C9.io , or StackBlitz.com may help you find the ease-of-use work-flow you are looking for, allowing you to partition your cloud work space in a completely customize-able manner. Drag and drop your Preview tab, your Terminal tab, or your script tags wherever you find it more convenient, and most importantly, get to the coding without all of the hassle!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM