์์ธ
Error: Not implemented: HTMLCanvasElement.prototype.getContext ์ค๋ฅ๋ ํ ์คํธ ํ๊ฒฝ์์ getContext ๋ฉ์๋๊ฐ ๊ตฌํ๋์ง ์์์ ๋ ๋ฐ์ํฉ๋๋ค.
์ด ์ค๋ฅ๋ ๋๊ฐ ํ ์คํธ ํ๊ฒฝ์์ ์บ๋ฒ์ค์ ๊ด๋ จ๋ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ๋ ๋ฐ์ํ๋๋ฐ, ํ ์คํธ ์ฝ๋์์ ์ค์ ๋ก ์บ๋ฒ์ค๋ฅผ ์ฌ์ฉํ๋ ค๋ ๊ฒ์ด ์๋๋ผ๋ฉด ์ด ์ค๋ฅ๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
๐๊ถ๊ธ์ฆ
context ๋ผ๋ ๊ฒ์ด react์ context๋ฅผ ์๋ฏธํ๋ ๊ฒ์ธ๊ฐ?
- HTMLCanvasElement.prototype.getContext ๋ฉ์๋์ "context"๋ฅผ ์๋ฏธ
- HTMLCanvasElement.prototype.getContext ๋ฉ์๋๋ HTML ์บ๋ฒ์ค ์์์ ๊ทธ๋ฆฌ๊ธฐ ์ปจํ ์คํธ๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฉ์๋
- ์ด ๋ฉ์๋๋ ์บ๋ฒ์ค ์์์ ์ปจํ ์คํธ ํ์ ์ ๋ฐ๋ผ ๋ค์ํ ๊ฐ์ ๋ฐํ.
- React์ ์ปจํ ์คํธ์๋ ์ง์ ์ ์ธ ์ฐ๊ด์ฑ์ด ์์
ํด๊ฒฐ ๋ฐฉ๋ฒ
- ์์กด์ฑ ์ฃผ์
yarn add --dev jest-canvas-mock
2. jest.config.js์ ์ ์ ์ค์ (setupFilesAfterEnv)
module.exports = {
testURL: 'http://localhost/',
testEnvironment: 'jsdom',
transform: {
'\\.[jt]sx?$': 'ts-jest',
},
setupFilesAfterEnv: ['jest-canvas-mock', '@babel/register'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/.erb/mocks/fileMock.js',
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
electron: '<rootDir>/.erb/mocks/electronMock.js',
},
transformIgnorePatterns: [
// '/node_modules/(?!(react-markdown|vfile|unist-util-stringify-position|unified|bail))',
],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
moduleDirectories: ['node_modules', 'release/app/node_modules'],
testPathIgnorePatterns: ['release/app/dist'],
setupFiles: ['./.erb/scripts/check-build-exists.ts', './test-setup.js'],
};
๊ทธ๋ผ์๋ ์ค๋ฅ๊ฐ ๋๋ค๋ฉด,
import 'jest-canvas-mock';
์ค๋ฅ๊ฐ ๋๋ ํ์ด์ง์ ํด๋น ์ฝ๋๋ฅผ importํ๋ฉด ํด๊ฒฐ๋๋ค!
๋๊ธ