node-tdd 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,9 +9,7 @@ export default (input, modifiers) => {
9
9
  const unknownModifiers = modifierNames
10
10
  .filter((n) => typeof modifiers[n] !== 'function');
11
11
  if (unknownModifiers.length !== 0) {
12
- // eslint-disable-next-line no-console
13
- console.warn(`Unknown Modifier(s) detected: ${unknownModifiers.join(', ')}`);
14
- return;
12
+ throw new Error(`Unknown Modifier(s) detected: ${unknownModifiers.join(', ')}`);
15
13
  }
16
14
  // eslint-disable-next-line no-param-reassign
17
15
  delete parent[k];
@@ -56,7 +56,9 @@ export default (() => {
56
56
  getLast: () => ({
57
57
  protocol: lastProtocol,
58
58
  options: lastOptions,
59
- body: lastBody.length === 0 ? undefined : lastBody.join('')
59
+ body: lastBody.length !== 0 || ['POST', 'PUT', 'PATCH'].includes(lastOptions.method)
60
+ ? lastBody.join('')
61
+ : undefined
60
62
  })
61
63
  };
62
64
  })();
@@ -178,10 +178,9 @@ export default (opts) => {
178
178
  scope.filteringRequestBody = (body) => {
179
179
  if (anyFlagPresent(['magic', 'body'])) {
180
180
  const idx = pendingMocks.findIndex((m) => m.idx === scopeIdx);
181
- const requestBody = tryParseJson(body);
182
- const requestBodyStr = nullAsString(requestBody);
183
- if (!isEqual(scope.body, requestBodyStr)) {
184
- pendingMocks[idx].record.body = requestBodyStr;
181
+ const requestBody = nullAsString(tryParseJson(body));
182
+ if (!isEqual(scope.body, requestBody)) {
183
+ pendingMocks[idx].record.body = requestBody;
185
184
  }
186
185
  return scope.body;
187
186
  }
@@ -215,6 +214,18 @@ export default (opts) => {
215
214
  interceptor.delayBody(pendingMocks[idx].record.delayBody);
216
215
  }
217
216
 
217
+ const hasSentBody = requestBodyString !== undefined;
218
+ // eslint-disable-next-line no-underscore-dangle
219
+ const hasRecordBody = interceptor._requestBody !== undefined;
220
+ if (hasSentBody !== hasRecordBody) {
221
+ if (anyFlagPresent(['magic', 'body'])) {
222
+ pendingMocks[idx].record.body = nullAsString(tryParseJson(requestBodyString));
223
+ } else {
224
+ // eslint-disable-next-line no-param-reassign
225
+ interceptor.errorMessage = 'Recording body mismatch';
226
+ }
227
+ }
228
+
218
229
  if (anyFlagPresent(['magic', 'headers'])) {
219
230
  // add new headers
220
231
  const reqheaders = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-tdd",
3
3
  "type": "module",
4
- "version": "5.0.0",
4
+ "version": "5.1.0",
5
5
  "description": "Drop in extension for mocha to abstract commonly used test setups",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {