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
The jest.setTimeout() sets default timeout for whole test file regardless of its actual placement in the file. The Jest API documentation mentions it, but it's not clear how this works under the hood. In fact, only last call applies and sets the timeout for all tests before they are started. As it might be tempting to place that command anywhere in the file, it would be useful to create an ESLint rule that:
checks if jest.setTimeout() is placed in global scope only (this itself would have immense value)
checks if jest.setTimeout() is only once in the file (nice to have)
checks if jest.setTimeout() is placed before any Jest test methods (before*, after*, test*, it*, describe*) (nice to have)
As an example, in this test file, the timeout for all tests is set to 800ms:
jest.setTimeout(1000);describe('A',()=>{beforeEach(async()=>{awaitnewPromise(resolve=>{setTimeout(resolve,10000).unref();});});// applied timeout: 800msit('A.1',async()=>{awaitnewPromise(resolve=>{setTimeout(resolve,10000).unref();});});// applied timeout: 800msjest.setTimeout(2000);it('A.2',async()=>{awaitnewPromise(resolve=>{setTimeout(resolve,10000).unref();});});// applied timeout: 800ms});jest.setTimeout(1500);describe('B',()=>{it('B.1',async()=>{awaitnewPromise(resolve=>{jest.setTimeout(1000);setTimeout(resolve,10000).unref();});});// applied timeout: 800msit('B.2',async()=>{awaitnewPromise(resolve=>{setTimeout(resolve,10000).unref();});});// applied timeout: 800msjest.setTimeout(500);});jest.setTimeout(800);// only value that applies
The text was updated successfully, but these errors were encountered:
The
jest.setTimeout()
sets default timeout for whole test file regardless of its actual placement in the file. The Jest API documentation mentions it, but it's not clear how this works under the hood. In fact, only last call applies and sets the timeout for all tests before they are started. As it might be tempting to place that command anywhere in the file, it would be useful to create an ESLint rule that:As an example, in this test file, the timeout for all tests is set to 800ms:
The text was updated successfully, but these errors were encountered: