File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
docs/engineering/javascript/test-double Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ # TestDouble.js: Stubbing Chained Methods
2
+
3
+ ``` typescript
4
+ td .replace (
5
+ config .getOptionalConfig ,
6
+ ' getOptionalConfig' ,
7
+ td .function (' config.getOptionalConfig' ),
8
+ )
9
+
10
+ td .when (config .getOptionalConfig (configKey )).thenReturn ({
11
+ getOptionalString: td .function (' getOptionalString' ),
12
+ })
13
+
14
+ const configStubs = [
15
+ { key: ' athenaRoleArn' , value: ' arn:aws:iam::123456789:role/dummy-role' },
16
+ { key: ' athenaRegion' , value: ' dummy-region' },
17
+ { key: ' athenaRoleSessionName' , value: ' dummy-session-name' },
18
+ { key: ' athenaCatalogName' , value: ' dummy-catalog-name' },
19
+ { key: ' athenaDatabaseName' , value: ' dummy-database-name' },
20
+ { key: ' athenaTableName' , value: ' dummy-table-name' },
21
+ { key: ' athenaResultOutputLocation' , value: ' dummy-output-location' },
22
+ ]
23
+
24
+ configStubs .forEach (({ key , value }) =>
25
+ td
26
+ .when (config .getOptionalConfig (configKey ).getOptionalString (key ))
27
+ .thenReturn (value ),
28
+ )
29
+ ```
Original file line number Diff line number Diff line change 68
68
- NPKill - node_modules : engineering/javascript/node/node-cleanup.md
69
69
- Jest :
70
70
- Helpful Tips : engineering/javascript/jest/helpful-tips.md
71
+ - Stubbing Chained Methods : engineering/javascript/test-double/stubbing-chained-methods.md
71
72
- Ruby :
72
73
- Handling JSON : engineering/ruby/handling-json.md
73
74
- Git :
You can’t perform that action at this time.
0 commit comments