mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
/**
|
|
* super stubber
|
|
* Ember's `_super` functionality is a little challenging to stub.
|
|
* The following will essentially let you stub `_super`, letting
|
|
* you test single units of code that use `_super`
|
|
* The return value is a function with the same signature as
|
|
* traditional `test` or `it` test functions. Any test code
|
|
* used within the cb 'sandbox' will use the stubbed `_super`.
|
|
* It's done this way to attempt to make it easy to reuse for various tests
|
|
* using the same stub in a recognisable way.
|
|
*
|
|
* @param {object} obj - The instance with the that `_super` belongs to
|
|
* @param {object} [stub=function(){return arguments}] -
|
|
* The stub to use in place of `_super`, if not specified `_super` will
|
|
* simply return the `arguments` passed to it
|
|
*
|
|
* @returns {function}
|
|
*/
|
|
export default function (obj, stub) {
|
|
const _super =
|
|
typeof stub === 'undefined'
|
|
? function () {
|
|
return arguments;
|
|
}
|
|
: stub;
|
|
/**
|
|
* @param {string} message - Message to accompany the test concept (currently unused)
|
|
* @param {function} cb - Callback that performs the test, will use the stubbed `_super`
|
|
* @returns The result of `cb`, and therefore maintain the same API
|
|
*/
|
|
return function (message, _cb) {
|
|
const cb = typeof message === 'function' ? message : _cb;
|
|
|
|
let orig = obj._super;
|
|
Object.defineProperty(Object.getPrototypeOf(obj), '_super', {
|
|
set: function () {},
|
|
get: function () {
|
|
return _super;
|
|
},
|
|
});
|
|
// TODO: try/catch this?
|
|
const actual = cb();
|
|
Object.defineProperty(Object.getPrototypeOf(obj), '_super', {
|
|
set: function (val) {
|
|
orig = val;
|
|
},
|
|
get: function () {
|
|
return orig;
|
|
},
|
|
});
|
|
return actual;
|
|
};
|
|
}
|