<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[&#96;@sinonjs&#x2F;fake-timers&#96;——模具行业从业者必备知识手册]]></title><description><![CDATA[<p dir="auto">&lt;h2&gt;<code>@sinonjs/fake-timers</code>&lt;/h2&gt;</p>
<p dir="auto">&lt;p&gt;&lt;a href="upload://tEz0gCXviVKsqN6M4CWo8X1sH7o.svg"&gt;&lt;img src="<a href="https://circleci.com/gh/sinonjs/fake-timers" rel="nofollow ugc">https://circleci.com/gh/sinonjs/fake-timers</a>" alt="CircleCI&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="upload://46ueXbt2Tr0Qczx21AwRpBtTjap.svg"&gt;&lt;img src="<a href="https://codecov.io/gh/sinonjs/fake-timers" rel="nofollow ugc">https://codecov.io/gh/sinonjs/fake-timers</a>" alt="codecov&lt;/a&gt;"&gt;&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="CODE_OF_CONDUCT.md"&gt;&lt;img src="upload://lkHxGIcGo50eOMGCuWB38Cks8lB.svg" alt="Contributor Covenant"&gt;&lt;/a&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;JavaScript implementation of the timer APIs; &lt;code&gt;setTimeout&lt;/code&gt;, &lt;code&gt;clearTimeout&lt;/code&gt;, &lt;code&gt;setImmediate&lt;/code&gt;, &lt;code&gt;clearImmediate&lt;/code&gt;, &lt;code&gt;setInterval&lt;/code&gt;, &lt;code&gt;clearInterval&lt;/code&gt;, &lt;code&gt;requestAnimationFrame&lt;/code&gt;, &lt;code&gt;cancelAnimationFrame&lt;/code&gt;, &lt;code&gt;requestIdleCallback&lt;/code&gt;, and &lt;code&gt;cancelIdleCallback&lt;/code&gt;, along with a clock instance that controls the flow of time. FakeTimers also provides a &lt;code&gt;Date&lt;/code&gt; implementation that gets its time from the clock.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;In addition in browser environment &lt;code&gt;@sinonjs/fake-timers&lt;/code&gt; provides a &lt;code&gt;performance&lt;/code&gt; implementation that gets its time from the clock. In Node environments FakeTimers provides a &lt;code&gt;nextTick&lt;/code&gt; implementation that is synchronized with the clock - and a &lt;code&gt;process.hrtime&lt;/code&gt; shim that works with the clock.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;&lt;code&gt;@sinonjs/fake-timers&lt;/code&gt; can be used to simulate passing time in automated tests and other&lt;/p&gt;<br />
&lt;p&gt;situations where you want the scheduling semantics, but don't want to actually&lt;/p&gt;<br />
&lt;p&gt;wait.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;&lt;code&gt;@sinonjs/fake-timers&lt;/code&gt; is extracted from &lt;a href="<a href="https://github.com/sinonjs/sinon.js" rel="nofollow ugc">https://github.com/sinonjs/sinon.js</a>"&gt;Sinon.JS&lt;/a&gt; and targets the &lt;a href="<a href="https://sinonjs.org/releases/latest/#supported-runtimes" rel="nofollow ugc">https://sinonjs.org/releases/latest/#supported-runtimes</a>"&gt;same runtimes&lt;/a&gt;.&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Autocomplete, IntelliSense and TypeScript definitions&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;Version 7 introduced JSDoc to the codebase. This should provide autocomplete and type suggestions in supporting IDEs. If you need more elaborate type support, TypeScript definitions for the Sinon projects are independently maintained by the Definitely Types community:&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
npm install -D @types/sinonjs__fake-timers<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;h3&gt;Installation&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;&lt;code&gt;@sinonjs/fake-timers&lt;/code&gt; can be used in both Node and browser environments. Installation is as easy as&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
npm install @sinonjs/fake-timers<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;If you want to use &lt;code&gt;@sinonjs/fake-timers&lt;/code&gt; in a browser you can either build your own bundle or use &lt;a href="<a href="https://www.skypack.dev" rel="nofollow ugc">https://www.skypack.dev</a>"&gt;Skypack&lt;/a&gt;.&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Usage&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;To use &lt;code&gt;@sinonjs/fake-timers&lt;/code&gt;, create a new clock, schedule events on it using the timer&lt;/p&gt;<br />
&lt;p&gt;functions and pass time using the &lt;code&gt;tick&lt;/code&gt; method.&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
// In the browser distribution, a global <code>FakeTimers</code> is already available<br />
var FakeTimers = require("@sinonjs/fake-timers");<br />
var clock = FakeTimers.createClock();</p>
<p dir="auto">clock.setTimeout(function () {<br />
console.log(<br />
"The poblano is a mild chili pepper originating in the state of Puebla, Mexico."<br />
);<br />
}, 15);</p>
<p dir="auto">// ...</p>
<p dir="auto">clock.tick(15);<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;p&gt;Upon executing the last line, an interesting fact about the&lt;/p&gt;<br />
&lt;p&gt;&lt;a href="<a href="https://en.wikipedia.org/wiki/Poblano" rel="nofollow ugc">https://en.wikipedia.org/wiki/Poblano</a>"&gt;Poblano&lt;/a&gt; will be printed synchronously to&lt;/p&gt;<br />
&lt;p&gt;the screen. If you want to simulate asynchronous behavior, you have to use your&lt;/p&gt;<br />
&lt;p&gt;imagination when calling the various functions.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;The &lt;code&gt;next&lt;/code&gt;, &lt;code&gt;runAll&lt;/code&gt;, &lt;code&gt;runToFrame&lt;/code&gt;, and &lt;code&gt;runToLast&lt;/code&gt; methods are available to advance the clock. See the&lt;/p&gt;<br />
&lt;p&gt;API Reference for more details.&lt;/p&gt;</p>
<p dir="auto">&lt;h4&gt;Faking the native timers&lt;/h4&gt;</p>
<p dir="auto">&lt;p&gt;When using &lt;code&gt;@sinonjs/fake-timers&lt;/code&gt; to test timers, you will most likely want to replace the native&lt;/p&gt;<br />
&lt;p&gt;timers such that calling &lt;code&gt;setTimeout&lt;/code&gt; actually schedules a callback with your&lt;/p&gt;<br />
&lt;p&gt;clock instance, not the browser's internals.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;Calling &lt;code&gt;install&lt;/code&gt; with no arguments achieves this. You can call &lt;code&gt;uninstall&lt;/code&gt;&lt;/p&gt;<br />
&lt;p&gt;later to restore things as they were again.&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
// In the browser distribution, a global <code>FakeTimers</code> is already available<br />
var FakeTimers = require("@sinonjs/fake-timers");</p>
<p dir="auto">var clock = FakeTimers.install();</p>
<hr />
<p dir="auto">还有什么补充参数吗？一起完善。<br />
&lt;/code&gt;&lt;/pre&gt;</p>
]]></description><link>https://forum.mj7.cn/topic/7260/sinonjs-fake-timers-模具行业从业者必备知识手册</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 07:36:16 GMT</lastBuildDate><atom:link href="https://forum.mj7.cn/topic/7260.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Apr 2026 22:21:17 GMT</pubDate><ttl>60</ttl></channel></rss>