_κΈ°λ₯_μ μμ²νμκ² μ΅λκΉ? μλλ©΄ _λ²κ·Έ_λ₯Ό λ³΄κ³ νμκ² μ΅λκΉ?
λ²κ·Έ μ κ³
νμ¬ νλμ 무μμ λκΉ?
Jest 16μμ: 0κ°μ μΈμλ‘ μ€νμ΄κ° νΈμΆλ λ 0κ°μ μΈμλ‘ toHaveBeenCalledWith
ν
μ€νΈλ ν΅κ³Όνμ§ μμ΅λλ€.
Jest 15μμ: 0κ°μ μΈμλ‘ μ€νμ΄κ° νΈμΆλ λ 0κ°μ μΈμλ‘ toHaveBeenCalledWith
ν
μ€νΈ ν΅κ³Ό
νμ¬ λμμ΄ λ²κ·ΈμΈ κ²½μ° μ¬ννλ λ¨κ³λ₯Ό μ 곡νκ³ κ°λ₯ν κ²½μ° npm install
λ° npm test
ν μ μλ GitHubμ μ΅μ μ μ₯μλ₯Ό μ 곡νμμμ€.
μ΅μ ν μ€νΈ:
it('can check that a function is called without arguments', () => {
let fn = jasmine.createSpy();
fn();
expect(fn).toHaveBeenCalledWith();
});
λ ν¬: https://github.com/benmccormick/jest-no-args/tree/master
μμλλ λμμ 무μμ λκΉ?
0κ°μ μΈμλ‘ toHaveBeenCalledWith
λ₯Ό μ¬μ©νμ¬ ν
μ€νΈνλ ν
μ€νΈλ 0κ°μ μΈμλ‘ μ€νμ΄κ° νΈμΆλ λ μ΄μ€μ
μ μ λ¬ν΄μΌ ν©λλ€.
--debug
λ‘ Jestλ₯Ό λ€μ μ€ννκ³ μΈμν μ 체 ꡬμ±μ μ 곡ν©λλ€.
> node_modules/.bin/jest --debug
jest version = 16.0.1
test framework = jasmine2
config = {
"rootDir": "/Users/ben/Code/experiments/jest-no-args",
"name": "-Users-ben-Code-experiments-jest-no-args",
"setupFiles": [],
"testRunner": "/Users/ben/Code/experiments/jest-no-args/node_modules/jest-jasmine2/build/index.js",
"scriptPreprocessor": "/Users/ben/Code/experiments/jest-no-args/node_modules/babel-jest/build/index.js",
"usesBabelJest": true,
"automock": false,
"bail": false,
"browser": false,
"cacheDirectory": "/var/folders/wy/1r3js80s60q497r_lrjyb0bh0000gn/T/jest",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"globals": {},
"haste": {
"providesModuleNodeModules": []
},
"mocksPattern": "__mocks__",
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"json",
"jsx",
"node"
],
"moduleNameMapper": {},
"modulePathIgnorePatterns": [],
"noStackTrace": false,
"notify": false,
"preset": null,
"preprocessorIgnorePatterns": [
"/node_modules/"
],
"resetModules": false,
"testEnvironment": "jest-environment-jsdom",
"testPathDirs": [
"/Users/ben/Code/experiments/jest-no-args"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$",
"testURL": "about:blank",
"timers": "real",
"useStderr": false,
"verbose": null,
"watch": false,
"cache": true,
"watchman": true,
"testcheckOptions": {
"times": 100,
"maxSize": 200
}
}
FAIL __tests__/test.js
β can check that a function is called without arguments
expect(spy).toHaveBeenCalledWith(expected)
Expected spy to have been called with:
[undefined]
But it was called with:
Array []
at Object.<anonymous>.it (__tests__/test.js:6:16)
at process._tickCallback (internal/process/next_tick.js:103:7)
β can check that a function is called without arguments (5ms)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.822s
Ran all test suites.
λ
Έλ λ²μ : 6.7.0
NPM λ²μ : 3.10.7
μ’μ, μ‘°κΈ νμ μ μνλ€. λ§€μ² μ체( /Users/ben/Code/experiments/jest/packages/jest-matchers/src/spyMatchers.js
μ μ μλ¨)λ μΈμκ° ν¨μμ μ λ¬λμ§ μμ λ λ λ²μ§Έ "μ μλμ§ μμ" μΈμλ‘ μ λ¬λ©λλ€. λ°λΌμ λ¬Έμ λ μλ§λ λ κΉμ κ²μ
λλ€(μΈμκ° μλ κ²κ³Ό λͺ
μμ μΌλ‘ undefinedλ₯Ό μ λ¬νλ κ²μ ꡬλ³νλ €λ κ² κ°μ΅λλ€).
μΈμ μ λ¬μ΄ μ΄λμμ λ°μνλμ§ μμ§ νμ€νμ§ μμ§λ§ κ°λ₯ν κ²½μ° νμ νκ³ PRμ μ΄λ €κ³ λ Έλ ₯ν κ²μ λλ€.
μ λ°μ΄νΈ: μ΄ λ¬Έμ λ₯Ό μΆμ νλ €λ©΄ λμμ΄ νμν κ² κ°μ΅λλ€. μ΄ λ§μ§λ§ λ¦΄λ¦¬μ€ λμ μ΄ λ§€μ²λ‘ μΆ©λΆν λ³κ²½λμ΄ μ΄κ²μ΄ μ΄λμ κ³ μ₯λ¬λμ§ μΆμ ν μ μμ΅λλ€.
κ·Έλ₯ νΈκΈ°μ¬μμ: toHaveBeenCalled()
λ₯Ό μ¬μ©νμ§ μκ² μ΅λκΉ?
'toHaveBeenCalled'λ ν¨μκ° μ ν νΈμΆλμλμ§ νμΈν©λλ€. μΈμ μμ΄ νΈμΆλ ν¨μλ₯Ό ꡬ체μ μΌλ‘ ν μ€νΈνλ ν μ€νΈκ° μμ΅λλ€.
μ€μ μ¬μ© μ¬λ‘: μ΄ ν¨μλ λͺ©λ‘μμ μλνλ©° idλ₯Ό μ·¨νκ±°λ(λ¨μΌ νλͺ©μ λν΄ μλ) id μμ΄ νΈμΆλκ³ (μ 체 λͺ©λ‘μμ μλν¨)
κ°μ₯ μ μ©ν λκΈ
'toHaveBeenCalled'λ ν¨μκ° μ ν νΈμΆλμλμ§ νμΈν©λλ€. μΈμ μμ΄ νΈμΆλ ν¨μλ₯Ό ꡬ체μ μΌλ‘ ν μ€νΈνλ ν μ€νΈκ° μμ΅λλ€.
μ€μ μ¬μ© μ¬λ‘: μ΄ ν¨μλ λͺ©λ‘μμ μλνλ©° idλ₯Ό μ·¨νκ±°λ(λ¨μΌ νλͺ©μ λν΄ μλ) id μμ΄ νΈμΆλκ³ (μ 체 λͺ©λ‘μμ μλν¨)