{"id":303525,"date":"2020-05-13T15:01:05","date_gmt":"2020-05-13T15:01:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303525"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303525","title":{"rendered":"\u041a\u0430\u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 setTimeout\/setInterval \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/501020\/\">\n<p>\u041c\u044b, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u043c \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b, \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430. \u0418 \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0438 \u0442\u0435\u0441\u0442\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438, \u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u043e\u0441\u0438\u043b\u0438 \u0431\u043e\u043b\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0438\u0445 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0448\u0430 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a &quot;<a href=\"https:\/\/wasaby.dev\/\">Wasaby<\/a>&quot; \u0438 \u043f\u0440\u043e\u0434\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 \u0435\u0433\u043e \u0431\u0430\u0437\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0435 \u0438 \u0434\u0435\u0441\u043a\u0442\u043e\u043f\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0420\u0435\u043b\u0438\u0437\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0443 \u043d\u0430\u0441 \u0436\u0435\u0441\u0442\u043a\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u044e, \u0430 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0439 \u0438\u043d\u0435\u0433\u0440\u0430\u0446\u0438\u0438. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/jenkins.io\/\">Jenkins<\/a> \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043e\u043a \u0438 <a href=\"https:\/\/mochajs.org\/\">Mocha<\/a> \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 <a href=\"https:\/\/www.chaijs.com\/api\/assert\/\">Chai assert<\/a> \u0434\u043b\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f JavaScript \u043a\u043e\u0434\u0430. \u0418 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0431\u043e\u0440\u043e\u043a \u0441\u0442\u0430\u043b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0445 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b JavaScript. \u0421\u0438\u043c\u043f\u0442\u043e\u043c\u0430\u0442\u0438\u043a\u0430 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430\u044f: \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u043b\u0438\u0431\u043e \u043d\u0435 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f, \u043b\u0438\u0431\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435 \u0442\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f. \u0418 \u0430\u043d\u0430\u043b\u0438\u0437 \u043a\u0435\u0439\u0441\u043e\u0432 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u044f\u0432\u043b\u044f\u0435\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u0442\u0435\u0441\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432\u044b\u0437\u043e\u0432\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <em>setTimeout<\/em> \u0438\u043b\u0438 <em>setInterval<\/em> \u0432 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c, \u043b\u0438\u0431\u043e \u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043a\u043e\u0434\u0435. \u041e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"pochemu-tak-proishodit\">\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?<\/h2>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432, \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043a\u0430\u043a-\u0442\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u0418 \u0442\u0435\u0441\u0442 \u043f\u0440\u0438\u0437\u0432\u0430\u043d \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u043c\u0443. \u041d\u043e \u0442.\u043a. \u043c\u044b \u0436\u0438\u0432\u0435\u043c \u043d\u0435 \u0432 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u0438\u0440\u0435, \u0442\u043e \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0442\u0435\u0441\u0442 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0431\u043e\u044e, \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0431\u044b\u043b \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u043a \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. \u0418 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0435\u0448\u0438\u0442\u044c, \u043a\u0430\u043a \u0436\u0435 \u0435\u043c\u0443 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u0434 \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430. \u0418 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043e\u043d \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">export class Foo {   propToTest: boolean = false;   methodToTest(): void {     setTimeout(() =&gt; {       this.propToTest = true;     }, 100);   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u043f\u0438\u0448\u0435\u0442 \u0442\u0435\u0441\u0442? \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043d \u043f\u043e\u0439\u0434\u0435\u0442 \u043f\u043e \u043f\u0443\u0442\u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u0435\u043d\u0438\u044f, \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0442\u043e\u0436\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 <em>setTimeout<\/em> \u0432 \u0442\u0435\u0441\u0442\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0437\u0430\u0434\u0430c\u0442 \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0449\u0438\u0439 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 101 \u043c\u0441 \u0432\u043c\u0435\u0441\u0442\u043e 100 \u043c\u0441). \u0412\u043e\u0442 \u0442\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">it('should set propToTest to true', (done: Function) =&gt; {   const inst = new Foo();   inst.methodToTest();   setTimeout(() =&gt; {     assert.isTrue(inst.propToTest);     done();   }, 101); });<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0433\u0440\u043e\u0437\u0438\u0442 \u043d\u0430\u0448\u0435\u043c\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443? \u0410 \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u0442.\u043a. \u0441\u0440\u0435\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/WindowOrWorkerGlobalScope\/setTimeout#Reasons_for_delays_longer_than_specified\">\u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442<\/a>, \u0447\u0442\u043e <em>callback<\/em>, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0432 <em>setTimeout<\/em>, \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d \u0442\u043e\u0447\u043d\u043e \u0441\u043f\u0443\u0441\u0442\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e \u2014 \u0435\u0441\u0442\u044c \u0448\u0430\u043d\u0441, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <a href=\"https:\/\/mochajs.org\/#-timeout-ms-t-ms\">\u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u0432 2 \u0441\u0435\u043a\u0443\u043d\u0434\u044b<\/a>, \u0447\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u0442\u0435\u0442 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u041d\u0430 \u044d\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u043b\u0438\u044f\u0435\u0442 \u043a\u0430\u043a \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0445 \u0432 \u0441\u0431\u043e\u0440\u043a\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432. \u0423 \u043d\u0430\u0441, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043f\u0435\u0440\u0438\u043e\u0434 \u0433\u0434\u0435-\u0442\u043e \u0437\u0430 \u043d\u0435\u0434\u0435\u043b\u044e \u0434\u043e \u0440\u0435\u043b\u0438\u0437\u0430 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u0430\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043e\u0448\u0438\u0431\u043e\u043a \u2014 \u0432 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043c\u044b \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u0432\u0441\u043f\u043b\u0435\u0441\u043a \u043d\u0430\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u0445.<br \/>  \u0412\u0441\u0435 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>setInterval<\/em>.<\/p>\n<p>  <\/p>\n<h2 id=\"kak-ne-nado-pytatsya-ispravit-situaciyu\">\u041a\u0430\u043a \u043d\u0435 \u043d\u0430\u0434\u043e \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e<\/h2>\n<p>  <\/p>\n<p>\u0421\u043f\u0443\u0441\u0442\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0430 \u0443\u043c \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043e\u043d\u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442. \u0421\u0440\u0430\u0437\u0443 \u043f\u043e\u043a\u0430\u0436\u0443, \u043d\u0430 \u043a\u0430\u043a\u0438\u0435 \u0433\u0440\u0430\u0431\u043b\u0438 \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0441\u0442\u0443\u043f\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0442\u0435\u0441\u0442\u0430.<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u0441\u0440\u043e\u0447\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 callback-\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0441\u0442\u0430, \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <em>setTimeout\/setInterval<\/em> (<em>&quot;\u0441\u0435\u0439\u0447\u0430\u0441 \u044f \u043d\u0430\u043f\u0438\u0448\u0443 1001 \u0432\u043c\u0435\u0441\u0442\u043e 101, \u0438 \u044d\u0442\u043e \u043c\u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442&quot;<\/em>). \u042d\u0442\u043e \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442.<\/li>\n<li>\u041d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b setTimeout() \u0432 \u0442\u0435\u0441\u0442\u0435 (<em>&quot;\u0441\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u0435\u0440\u0435\u043a\u0438\u043d\u0443 \u044d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 event loop, \u0438 \u044d\u0442\u043e \u043c\u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442&quot;<\/em>). \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442.<\/li>\n<li>(\u0415\u0441\u043b\u0438 \u0432\u044b \u0432\u0441\u0435 \u0436\u0435 \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0443\u043d\u043a\u0442\u044b 1 \u0438 2) \u041d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c <a href=\"https:\/\/mochajs.org\/#timeouts\">\u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430<\/a> \u2014 \u044d\u0442\u0430 \u043f\u043e\u0440\u043e\u0447\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043c\u0430\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u0435\u0441\u0442\u044b, \u0447\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u043e\u0431\u0449\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0430 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u0442\u0441\u044f.<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"kak-zhe-napisat-test-horosho\">\u041a\u0430\u043a \u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u0445\u043e\u0440\u043e\u0448\u043e?<\/h2>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u043c\u043d\u043e\u0433\u043e\u0433\u0440\u0430\u043d\u043d\u044b\u0439, \u0438 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0432\u043b\u043e\u0436\u0438\u0442\u0441\u044f \u0432 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438. \u042f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u043c\u043e\u0435\u0439 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438: \u043e\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043a \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c. \u041d\u043e \u0432\u044b \u0432\u043f\u0440\u0430\u0432\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0430\u0448\u0435\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<p>  <\/p>\n<ol>\n<li>\n<p>\u0423\u0431\u0440\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u0442\u0435\u0441\u0442\u0430 \u043f\u0443\u0442\u0435\u043c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043a\u043e\u0434\u0430 \u2014 \u0442.\u0435. \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b\u043c \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  \u0412 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u043d\u043e\u0441\u0438\u043c \u043a\u043e\u0434, \u043c\u0435\u043d\u044f\u044e\u0449\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430, \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">export function setProperState(inst: Foo) {   inst.propToTest = true; }  export class Foo {   propToTest: boolean = false;   methodToTest(): void {     setTimeout(() =&gt; {       setProperState(this);     }, 100);   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">it('should set propToTest to true', () =&gt; {   const inst = new Foo();   assert.isFalse(inst.propToTest);   setProperState(inst);   assert.isTrue(inst.propToTest); });<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0435\u043d, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u044b\u0437\u043e\u0432 <em>setProperState<\/em> \u0432\u043d\u0443\u0442\u0440\u0438 <em>methodToTest<\/em> (\u043c\u0435\u0442\u043e\u0434\u0438\u043a\u0443 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435). \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u0432\u0441\u0435 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u043e\u0431\u0449\u0438\u0439 \u0441\u043c\u044b\u0441\u043b \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f: \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0438 \u0443\u043f\u0440\u043e\u0449\u0430\u0439\u0442\u0435 \u043a\u043e\u0434, \u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0414\u0430, \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u043d\u043e \u043e\u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u0433\u043e.<\/p>\n<p>  <\/li>\n<li>\n<p>\u0423\u0431\u0440\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043e\u0441\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430, \u043d\u043e \u043c\u0435\u043d\u0435\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u043e\u0433\u043e.<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>setTimeout<\/em> \u043d\u0430 \u0441\u0432\u043e\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">export class Foo {   propToTest: boolean = false;   constructor(readonly awaiter: Function = setTimeout) {   }   methodToTest(): void {     this.awaiter(() =&gt; {       this.propToTest = true;     }, 100);   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0442\u0435\u0441\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u043a-\u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">it('should set propToTest to true', () =&gt; {   const awaiter = (callback) =&gt; callback();   const inst = new Foo(awaiter);   inst.methodToTest();   assert.isTrue(inst.propToTest); });<\/code><\/pre>\n<p>  <\/li>\n<li>\n<p>\u041e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <em>Promise<\/em>.<br \/>  \u041d\u0435 \u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u0432 \u0442\u0435\u0441\u0442\u0435 \u043f\u043e\u0434\u0433\u0430\u0434\u0430\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u2014 \u0432\u0435\u0434\u044c \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c. \u0410 \u041c\u043e\u043a\u043a\u0430 \u043e\u0442\u043b\u0438\u0447\u043d\u043e <a href=\"https:\/\/mochajs.org\/#working-with-promises\">\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043f\u0440\u043e\u043c\u0438\u0437\u0430\u043c\u0438<\/a>. \u041d\u043e \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">export class Foo {   propToTest: boolean = false;   methodToTest(): Promise&lt;void&gt; {     return new Promise((resolve) =&gt; {       setTimeout(() =&gt; {         this.propToTest = true;         resolve();       }, 100);      });   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <em>setTimeout<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">it('should set propToTest to true', () =&gt; {   const inst = newFoo();   return inst.methodToTest().then(() =&gt; {     assert.isTrue(inst.propToTest);   }); });<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430, \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u0438 \u0442\u0435\u0441\u0442 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0435 \u0435\u043c\u0443 \u0432\u0440\u0435\u043c\u044f, \u043d\u043e \u044d\u0442\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c &quot;\u0433\u0430\u0434\u0430\u0442\u044c \u043d\u0430 \u043a\u043e\u0444\u0435\u0439\u043d\u043e\u0439 \u0433\u0443\u0449\u0435&quot;. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0438\u043e\u0434\u0430 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0434\u043b\u044f <em>setTimeout<\/em> \u0432 \u0432\u0438\u0434\u0435 \u043e\u043f\u0446\u0438\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">export class Foo {   propToTest: boolean = false;   constructor(readonly asyncTimeout: number = 100) {   }   methodToTest(): void {     return new Promise((resolve) =&gt; {       setTimeout(() =&gt; {         this.propToTest = true;         resolve();       }, this.asyncTimeout);      });   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430 \u043c\u0438\u043d\u0438\u043c\u0443\u043c.<\/p>\n<p>  <\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c fake timers.<br \/>  \u041f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/sinonjs.org\/\">Sinon.JS<\/a> \u0438\u043c\u0435\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u043e\u0435 <a href=\"https:\/\/sinonjs.org\/releases\/latest\/fake-timers\/\">\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u0430\u043c\u0438<\/a>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 <a href=\"https:\/\/sinonjs.org\/how-to\/lolex-async-promises\/\">\u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0441\u0442\u0435\u043a \u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439<\/a>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u043d\u0435 \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u0434 \u0432\u043e\u043e\u0431\u0449\u0435 (\u0432 \u0438\u0434\u0435\u0430\u043b\u0435), \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <em>setTimeout<\/em> \u0438\u0437 \u0442\u0435\u0441\u0442\u0430.<br \/>  \u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0434 \u043a\u0430\u043a \u0435\u0441\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">export class Foo {   propToTest: boolean = false;   methodToTest(): void {     setTimeout(() =&gt; {       this.propToTest = true;     }, 100);   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0432 \u0442\u0435\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c fake timer, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u0435\u0441\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c(!):<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">let clock;  beforeEach(() =&gt; {   clock = sinon.useFakeTimers(); });  afterEach(() =&gt; {   clock.restore(); });  it('should set propToTest to true', () =&gt; {   const inst = newFoo();   inst.methodToTest();   clock.tick(101);   assert.isTrue(inst.propToTest); });<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435 &quot;\u043a\u0430\u043a \u0431\u044b\u043b\u043e&quot; \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 <em>clock.restore()<\/em>, \u0438\u043d\u0430\u0447\u0435 \u0440\u0438\u0441\u043a\u0443\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0441\u043e\u0441\u0435\u0434\u0430.<\/p>\n<p>  <\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"moral\">\u041c\u043e\u0440\u0430\u043b\u044c<\/h2>\n<p>  <\/p>\n<p>\u042e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b \u0434\u0430\u044e\u0442 \u0432\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0435 \u043c\u0435\u0441\u0442\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0432\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435. \u0418 \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0448\u0430\u043d\u0441 \u0447\u0442\u043e-\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u043e \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u0443. \u0412\u0435\u0434\u044c \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043b\u0435\u0433\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0438 \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0430 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/501020\/\"> https:\/\/habr.com\/ru\/company\/tensor\/blog\/501020\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/tensor\/blog\/501020\/\">\n<p>\u041c\u044b, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u043c \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b, \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430. \u0418 \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0438 \u0442\u0435\u0441\u0442\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438, \u0430 \u043d\u0435 \u043f\u0440\u0438\u043d\u043e\u0441\u0438\u043b\u0438 \u0431\u043e\u043b\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0438\u0445 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0448\u0430 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a &quot;<a href=\"https:\/\/wasaby.dev\/\">Wasaby<\/a>&quot; \u0438 \u043f\u0440\u043e\u0434\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 \u0435\u0433\u043e \u0431\u0430\u0437\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0435 \u0438 \u0434\u0435\u0441\u043a\u0442\u043e\u043f\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0420\u0435\u043b\u0438\u0437\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0443 \u043d\u0430\u0441 \u0436\u0435\u0441\u0442\u043a\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u044e, \u0430 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0439 \u0438\u043d\u0435\u0433\u0440\u0430\u0446\u0438\u0438. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/jenkins.io\/\">Jenkins<\/a> \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043e\u043a \u0438 <a href=\"https:\/\/mochajs.org\/\">Mocha<\/a> \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 <a href=\"https:\/\/www.chaijs.com\/api\/assert\/\">Chai assert<\/a> \u0434\u043b\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f JavaScript \u043a\u043e\u0434\u0430. \u0418 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0441\u0431\u043e\u0440\u043e\u043a \u0441\u0442\u0430\u043b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u0432\u0441\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0445 \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b JavaScript. \u0421\u0438\u043c\u043f\u0442\u043e\u043c\u0430\u0442\u0438\u043a\u0430 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430\u044f: \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u043b\u0438\u0431\u043e \u043d\u0435 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f, \u043b\u0438\u0431\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435 \u0442\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f. \u0418 \u0430\u043d\u0430\u043b\u0438\u0437 \u043a\u0435\u0439\u0441\u043e\u0432 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u044f\u0432\u043b\u044f\u0435\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u0442\u0435\u0441\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432\u044b\u0437\u043e\u0432\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <em>setTimeout<\/em> \u0438\u043b\u0438 <em>setInterval<\/em> \u0432 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c, \u043b\u0438\u0431\u043e \u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u043c \u043a\u043e\u0434\u0435. \u041e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-303525","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303525"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303525\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}