Skip to content

Commit

Permalink
AG-13199 rename noopThrow helper into throwFunc
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/scriptlets from fix/AG-13199_01 to release/v1.8

Squashed commit of the following:

commit 0278bdf
Merge: 1fe4d3b b2624bf
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Wed Dec 28 17:48:57 2022 +0300

    Merge branch 'release/v1.8' into fix/AG-13199_01

commit 1fe4d3b
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Wed Dec 28 17:32:01 2022 +0300

    rename noopThrow helper into throwFunc
  • Loading branch information
stanislav-atr committed Dec 28, 2022
1 parent b2624bf commit 89185d3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Unreleased 1.8.x

### Added
- `noopThrow` and `noopCallbackFunc` prop values for `set-constant` scriptlet
- `throwFunc` and `noopCallbackFunc` prop values for `set-constant` scriptlet

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/noop-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const noopObject = () => ({});
* Function throws an error
* @throws
*/
export const noopThrow = () => {
export const throwFunc = () => {
throw new Error();
};

Expand Down
10 changes: 5 additions & 5 deletions src/scriptlets/set-constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
noopFunc,
trueFunc,
falseFunc,
noopThrow,
throwFunc,
noopPromiseReject,
noopPromiseResolve,
getPropertyInChain,
Expand Down Expand Up @@ -58,7 +58,7 @@ import {
* - `noopCallbackFunc` - function returning noopFunc
* - `trueFunc` - function returning true
* - `falseFunc` - function returning false
* - `noopThrow` - function throwing an error
* - `throwFunc` - function throwing an error
* - `noopPromiseResolve` - function returning Promise object that is resolved with an empty response
* - `noopPromiseReject` - function returning Promise.reject()
* - `''` - empty string
Expand Down Expand Up @@ -122,8 +122,8 @@ export function setConstant(source, property, value, stack) {
constantValue = trueFunc;
} else if (value === 'falseFunc') {
constantValue = falseFunc;
} else if (value === 'noopThrow') {
constantValue = noopThrow;
} else if (value === 'throwFunc') {
constantValue = throwFunc;
} else if (value === 'noopPromiseResolve') {
constantValue = noopPromiseResolve;
} else if (value === 'noopPromiseReject') {
Expand Down Expand Up @@ -294,7 +294,7 @@ setConstant.injections = [
noopCallbackFunc,
trueFunc,
falseFunc,
noopThrow,
throwFunc,
noopPromiseReject,
noopPromiseResolve,
getPropertyInChain,
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/noop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
noopPromiseResolve,
noopCallbackFunc,
noopFunc,
noopThrow,
throwFunc,
} from '../../src/helpers';

const { test, module } = QUnit;
Expand Down Expand Up @@ -35,6 +35,6 @@ test('noopCallbackFunc returns noopFunc', async (assert) => {
assert.strictEqual(func(), undefined, 'function returns undefined');
});

test('noopThrow throws an error', async (assert) => {
assert.throws(() => noopThrow(), 'noopThrow throws an error');
test('throwFunc throws an error', async (assert) => {
assert.throws(() => throwFunc(), 'throwFunc throws an error');
});
8 changes: 4 additions & 4 deletions tests/scriptlets/set-constant.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ if (!isSupported) {
clearGlobalProps(noopCallbackFuncProp);

// setting constant to noopCallbackFunc;
const noopThrowProp = 'noopThrow';
runScriptletFromTag(noopThrowProp, 'noopThrow');
assert.throws(() => window[noopThrowProp]()(), 'noopThrowProp throws an error');
clearGlobalProps(noopThrowProp);
const throwFuncProp = 'throwFunc';
runScriptletFromTag(throwFuncProp, 'throwFunc');
assert.throws(() => window[throwFuncProp]()(), 'throwFuncProp throws an error');
clearGlobalProps(throwFuncProp);

// setting constant to trueFunc;
const trueFuncProp = 'trueFuncProp';
Expand Down

0 comments on commit 89185d3

Please sign in to comment.