Skip to content

Commit 75cc5bd

Browse files
committed
translate testing-with-mocks.md
1 parent cc8943a commit 75cc5bd

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

โ€Ždocs/ko/workflow/testing-with-mocks.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Testing with Mocks
1+
# ๋ชฉ์—…์„ ์œ„ํ•œ ํ…Œ์ŠคํŠธ
22

3-
In a real world application, our components most likely have external dependencies. When writing unit tests for components, it would be ideal if we can mock these external dependencies so that our tests only rely the behavior of the component being tested.
3+
๋ฆฌ์–ผ ์›”๋“œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ์ปดํฌ๋„ŒํŠธ์— ์™ธ๋ถ€ ์˜์กด์„ฑ์ด ์žˆ์„ ๊ฐ€๋Šฅ์„ฑ์ด ํฝ๋‹ˆ๋‹ค. ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ์œ ๋‹› ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ํ…Œ์ŠคํŠธ๊ฐ€ ํ…Œ์ŠคํŠธ ์ค‘์ธ ์ปดํฌ๋„ŒํŠธ์˜ ๋™์ž‘์—๋งŒ ์˜์กดํ•˜๋„๋ก mock์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์ด์ƒ์  ์ž…๋‹ˆ๋‹ค.
44

5-
`vue-loader` provides a feature that allows you to inject arbitrary dependencies to a `*.vue` component, using [inject-loader](https://github.com/plasticine/inject-loader). The general idea is that instead of directly importing the component module, we use `inject-loader` to create a "module factory" function for that module. When this function gets called with an object of mocks, it returns an instance of the module with the mocks injected.
5+
`vue-loader`๋Š” [inject-loader](https://github.com/plasticine/inject-loader)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž„์˜์˜ ์˜์กด์„ฑ์„ `*.vue` ์ปดํฌ๋„ŒํŠธ์— ์ฃผ์ž… ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์ธ ์•„์ด๋””์–ด๋กœ ์ปดํฌ๋„ŒํŠธ ๋ชจ๋“ˆ์„ ์ง์ ‘ ๊ฐ€์ ธ์˜ค๋Š” ๋Œ€์‹  `inject-loader`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•ด๋‹น ๋ชจ๋“ˆ์— ๋Œ€ํ•œ "๋ชจ๋“ˆ ํŒฉํ† ๋ฆฌ" ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ ์ž…๋‹ˆ๋‹ค. ์ด ํ•จ์ˆ˜๊ฐ€ mock ๊ฐ์ฒด์™€ ํ•จ๊ป˜ ํ˜ธ์ถœ๋˜๋ฉด mock ๊ฐ์ฒด๊ฐ€ ์‚ฝ์ž…๋œ ๋ชจ๋“ˆ์˜ ์ธ์Šคํ„ดํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
66

7-
Suppose we have a component like this:
7+
๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ด์‹ฟ๊ณ  ๊ฐ€์ •ํ•ด๋ด…์‹œ๋‹ค.
88

99
``` html
1010
<!-- example.vue -->
@@ -26,9 +26,9 @@ export default {
2626
</script>
2727
```
2828

29-
Here's how to import it with mocks:
29+
mock์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
3030

31-
> Note: [email protected] is currently unstable.
31+
> ์ฃผ์˜: `[email protected]`๋Š” ํ˜„์žฌ ๋ถˆ์•ˆ์ •ํ•ฉ๋‹ˆ๋‹ค.
3232
3333
``` bash
3434
npm install inject-loader@^2.0.0 --save-dev
@@ -39,12 +39,12 @@ npm install inject-loader@^2.0.0 --save-dev
3939
const ExampleInjector = require('!!vue?inject!./example.vue')
4040
```
4141

42-
Notice that crazy require string - we are using some inline [webpack loader requests](https://webpack.github.io/docs/loaders.html) here. A quick explanation:
42+
Notice that crazy require string. ์—ฌ๊ธฐ์—๋Š” ์ธ๋ผ์ธ [webpack loader requests](https://webpack.github.io/docs/loaders.html)์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ๊ฐ„๋‹จํ•œ ์„ค๋ช…์„ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
4343

44-
- `!!` at the start means "disable all loaders from the global config";
45-
- `vue?inject!` means "use the `vue` loader, and pass in the `?inject` query". This tells `vue-loader` to compile the component in dependency-injection mode.
44+
- `!!`๋Š” "๊ธ€๋กœ๋ฒŒ ์„ค์ •์—์„œ ๋ชจ๋“  ๋กœ๋”๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ํ•จ"์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
45+
- `vue?inject!`๋Š” `vue` ๋กœ๋”๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  `?inject` ์ฟผ๋ฆฌ๋ฅผ ์ „๋‹ฌํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ `vue-loader`์—๊ฒŒ ์˜์กด์„ฑ ์ฃผ์ž… ๋ชจ๋“œ๋กœ ์ปดํผ๋„ŒํŠธ๋ฅผ ์ปดํŒŒ์ผํ•˜๋„๋ก ์•Œ๋ ค์ค๋‹ˆ๋‹ค.
4646

47-
The returned `ExampleInjector` is a factory function that can be called to create instances of the `example.vue` module:
47+
๋ฐ˜ํ™˜๋œ `ExampleInjector`๋Š” `example.vue` ๋ชจ๋“ˆ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ํ˜ธ์ถœ ๋  ์ˆ˜ ์žˆ๋Š” ํŒฉํ† ๋ฆฌ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
4848

4949
``` js
5050
const ExampleWithMocks = ExampleInjector({
@@ -55,7 +55,7 @@ const ExampleWithMocks = ExampleInjector({
5555
})
5656
```
5757

58-
Finally, we can test the component like usual:
58+
๋งˆ์ง€๋ง‰์œผ๋กœ ์šฐ๋ฆฌ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ‰์ƒ์‹œ์— ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
5959

6060
``` js
6161
it('should render', () => {

0 commit comments

Comments
ย (0)