sourcetip

테스트 파일에서 테스트 하나 건너뛰기 Jest

fileupload 2023. 8. 26. 12:08
반응형

테스트 파일에서 테스트 하나 건너뛰기 Jest

저는 Jest 프레임워크를 사용하고 있으며 테스트 스위트가 있습니다.테스트 중 하나를 끄거나 건너뜁니다.

구글 문서는 답을 제공하지 않습니다.

당신은 확인해야 할 답이나 정보의 출처를 알고 있습니까?

여기서 답을 찾았습니다.

https://devhints.io/jest

test('it is raining', () => {
  expect(inchesOfRain()).toBeGreaterThan(0);
});

test.skip('it is not snowing', () => {
  expect(inchesOfSnow()).toBe(0);
});

문서에서 링크 해제

제외할 수도 있습니다.test또는describe그들 앞에 an을 붙임으로써.x.

개별 테스트

describe('All Test in this describe will be run', () => {
  xtest('Except this test- This test will not be run', () => {
   expect(true).toBe(true);
  });
  test('This test will be run', () => {
   expect(true).toBe(true);
  });
});

설명 내부의 다중 검정

xdescribe('All tests in this describe will be skipped', () => {
 test('This test will be skipped', () => {
   expect(true).toBe(true);
 });

 test('This test will be skipped', () => {
   expect(true).toBe(true);
 });
});

테스트 건너뛰기

Jest에서 테스트를 건너뛰려면 test.skip:

test.skip(name, fn)

또한 다음 별칭 아래에 있습니다.

  • it.skip(name, fn)또는
  • xit(name, fn)또는
  • xtest(name, fn)

테스트 제품군 건너뛰기

또한 테스트 스위트를 건너뛰려면 설명을 사용할 수 있습니다.건너뛰기:

describe.skip(name, fn)

또한 다음 별칭 아래에 있습니다.

  • xdescribe(name, fn)

저는 여기에 떨어질지도 모르는 사람들을 위해 이 대답을 덧붙이고 싶습니다.내가 나 자신을 찾으면서.

[only, skip, aliases(더 자세한 정보), docref, 다양한 변형(각각, 동시, 실패), 테스트 파일을 무시하는 방법(마지막 섹션)]

스킴이 가능합니다.섹션을 가져옵니다.

파일 내에서 하나만 건너뛰거나 실행

skip » [문서 참조 포함]

사용하다.skip()테스트 또는 테스트 세트를 건너뛰는 기능(계속)

test('something', () => {})

=>

test.skip('something', () => {})

별칭을 사용할 수 있습니다.

xtest('something', () => {})

▁to도 입니다.it그것도 가명입니다.

it.skip('something', () => {})
xit('something', () => {})

당분간descripe:

describe.skip(() => {})
xdescribe(() => {})

문서:
https://jestjs.io/docs/api#://jestjs.io/docs/api#testskipname-fn
https://jestjs.io/docs/api#://jestjs.io/docs/api#describeskipname-fn

별칭은 요소 제목 아래에서 찾을 수 있습니다.

enter image description here

편집기를 통해 @types/jest가 설치된 경우에도 테스트할 수 있습니다.

enter image description here

ftest예를 들어 종료하지 않습니다.only()부분.

참고 사항:

test.skip.each(table)(name, fn)

데이터 기반 테스트의 경우.동일한 별칭도 적용됩니다.아래 참조를 확인합니다.

참조: https://jestjs.io/docs/api#testskipeachtablename-fn

동일:

test.concurrent.skip.each(table)(name, fn)

동시 테스트의 경우.이 항목에 대한 x 별칭이 없습니다.아래 참조를 확인합니다.

참조: https://jestjs.io/docs/api#testconcurrentskipeachtablename-fn

그리고.

describe.skip.each(table)(name, fn)

참조: https://jestjs.io/docs/api#describeskipeachtablename-fn

test.skip.failing(name, fn, timeout)

참조: https://jestjs.io/docs/api#testskipfailingname-fn-timeout

겨우 ()

사용하다only()해당 테스트만 실행하고 다른 테스트는 수행하지 않을 경우.

사용할 수 있습니다.only()여러 개의 테스트 또는 테스트 스위트(복수)와 함께 제공됩니다.이 경우에는 다음을 수행할 수 있습니다.only()에 되었습니다.

참고: 파일 수준에서만 작동합니다.그리고 모든 파일을 교차하지 않습니다.

test('test 1', () => {})
test('test 2', () => {})
test('test 3', () => {})
test.only('test 4', () => {}) // only this would run in this file

여러 개:

test('test 1', () => {})
test.only('test 2', () => {}) // only this
test('test 3', () => {})
test.only('test 4', () => {}) // and this would run in this file

설명 포함:

describe(() => {
   test('test 1', () => {})       // nothing will run here
   test.only('test 2', () => {}) // 
})

describe.only(() => {
   test('test 1', () => {})
   test.only('test 2', () => {}) // only this test
   test('test 3', () => {})
   test.only('test 4', () => {}) // and this one would be run (because this is the only active describe block) 
})

describe(() => {
   test('test 1', () => {}).      // No test will run here
   test.only('test 2', () => {}) //
})

에 대한 별칭():

추가f하지만 조심하세요. ftest()별칭이 아닙니다!!!!

it.only()
fit()
describe.only()
fdescribe()
ftest() // WRONG ERROR !!! No such an alias SADLY!!!

뭐, 슬프지도 않아요.저는 개인적으로 사용하는 것을 선호합니다.only()더 장황하고 읽을 수 있기 때문에.

문서:
https://jestjs.io/docs/api#testonlyname-fn-timeout
https://jestjs.io/docs/api#describeonlyname-fn

참고 사항:

describe.only.each(table)(name, fn)

참조: https://jestjs.io/docs/api#describeonlyeachtablename-fn

test.concurrent.only.each(table)(name, fn)

참조: https://jestjs.io/docs/api#testconcurrentonlyeachtablename-fn

test.only.failing(name, fn, timeout)

참조: https://jestjs.io/docs/api#testonlyfailingname-fn-timeout

config 또는 cli를 사용하여 테스트 무시

이 섹션은 전체 파일을 무시하는 방법을 검색하던 사용자를 위한 것입니다.

테스트 경로 무시 패턴

정규식 (regex not glob)정규식이 일치하는 경우 무시할 테스트 파일의 개수입니다.

https://jestjs.io/docs/configuration#testpathignorepatterns-arraystring

Github 이슈 ref

예:

jest.config.ts

import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  verbose: true,
  automock: false,
  testPathIgnorePatterns: ['.*/__fixtures__/.*'] // here
};

export default config;

또는 CLI 사용:

참조: https://jestjs.io/docs/cli#--testpathignorepatternsregexarray

jest --testPathIgnorePatterns=".*/__fixtures__/.*"

배열(복수 정규식)의 경우:

여러 가지 방법이 있습니다.

# one regex with or operator `|` 
jest --testPathIgnorePatterns=".*/__fixtures__/.*|<rootDir>/src/someDir/"

# paranthesis with spaces
jest --testPathIgnorePatterns="\(.*/__fixtures__/.* <rootDir>/src/someDir/\)"

# using the argument multiple times
jest --testPathIgnorePatterns=".*/__fixtures__/.*" --testPathIgnorePatterns="<rootDir>/src/someDir/"

testMatch

testMatch는 실행할 항목을 결정하는 또 다른 방법이 될 수 있습니다(예:only())

를 사용합니다.globs그리고 아닌 regex

참조: https://jestjs.io/docs/configuration#testmatch-arraystring

전역 부정을 사용하여 일부 파일을 무시할 수도 있습니다.

예:

{
  // ... rest of the package
  "jest": {
    "testMatch": [
      "**/__tests__/**/!(DISABLED.)*.[jt]s?(x)",
      "**/!(DISABLED.)?(*.)+(spec|test).[tj]s?(x)"
    ]
  }
}

CLI 버전도 있습니다.

https://jestjs.io/docs/cli#--testmatch-glob1--globn

인수가 없는 경우

jest my-test #or
jest path/to/my-test.js
jest **/some/**/*.spec.*

그러면 패턴과 일치하는 테스트 파일만 실행됩니다.

참조: https://jestjs.io/docs/cli#running-from-the-command-line

일부 검정만 실행:

테스트가 많은 테스트 제품군에서 테스트를 디버깅/쓰기/확장하는 경우 작업 중인 테스트를 실행하기만 하면 되지만,.skip누구에게나 고통스러울 수 있습니다.

그렇게.only구조하러 옵니다.다음을 사용하여 테스트하는 동안 다른 항목을 건너뛸 수 있습니다..only플래그, 테스트를 추가하거나 디버그해야 하는 대형 제품군에 매우 유용할 수 있습니다.

describe('some amazing test suite', () => {
  test('number one', () => {
    // some testing logic
  }
  test('number two', () => {
    // some testing logic
  }
  ...
  test('number x', () => {
    // some testing logic
  }
  test.only('new test or the one needs debugging', () => {
    // Now when you run this suite only this test will run
    // so now you are free to debug or work on business logic
    // instead to wait for other tests to pass every time you run jest
    // You can remove `.only` flag once you're done!
  }
}

추가할 수도 있습니다..only여러 개를 동시에 실행하려는 경우 테스트 스위트 또는 파일에 있는 두 개 이상의 테스트로!

언급URL : https://stackoverflow.com/questions/48125230/skip-one-test-in-test-file-jest

반응형