Move private APIs to private namespace

Fixes #2078
This commit is contained in:
Steve Gravrock
2025-09-27 13:21:09 -07:00
parent fbec066837
commit 168ff0a751
183 changed files with 2627 additions and 2459 deletions

View File

@@ -1,19 +1,19 @@
describe('SpyStrategy', function() {
it('defaults its name to unknown', function() {
const spyStrategy = new jasmineUnderTest.SpyStrategy();
const spyStrategy = new privateUnderTest.SpyStrategy();
expect(spyStrategy.identity).toEqual('unknown');
});
it('takes a name', function() {
const spyStrategy = new jasmineUnderTest.SpyStrategy({ name: 'foo' });
const spyStrategy = new privateUnderTest.SpyStrategy({ name: 'foo' });
expect(spyStrategy.identity).toEqual('foo');
});
it('stubs an original function, if provided', function() {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.exec();
@@ -22,7 +22,7 @@ describe('SpyStrategy', function() {
it("allows an original function to be called, passed through the params and returns it's value", function() {
const originalFn = jasmine.createSpy('original').and.returnValue(42),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.callThrough();
const returnValue = spyStrategy.exec(null, ['foo']);
@@ -34,7 +34,7 @@ describe('SpyStrategy', function() {
it('can return a specified value when executed', function() {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.returnValue(17);
const returnValue = spyStrategy.exec();
@@ -45,7 +45,7 @@ describe('SpyStrategy', function() {
it('can return specified values in order specified when executed', function() {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.returnValues('value1', 'value2', 'value3');
@@ -58,7 +58,7 @@ describe('SpyStrategy', function() {
it('allows an exception to be thrown when executed', function() {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.throwError(new TypeError('bar'));
@@ -70,7 +70,7 @@ describe('SpyStrategy', function() {
it('allows a string to be thrown, wrapping it into an exception when executed', function() {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.throwError('bar');
@@ -82,7 +82,7 @@ describe('SpyStrategy', function() {
it('allows a non-Error to be thrown when executed', function() {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.throwError({ code: 'ESRCH' });
@@ -95,7 +95,7 @@ describe('SpyStrategy', function() {
it('allows a fake function to be called instead', function() {
const originalFn = jasmine.createSpy('original'),
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.callFake(fakeFn);
const returnValue = spyStrategy.exec();
@@ -109,7 +109,7 @@ describe('SpyStrategy', function() {
fakeFn = jasmine.createSpy('fake').and.callFake(async () => {
return 67;
}),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.callFake(fakeFn);
spyStrategy
@@ -128,7 +128,7 @@ describe('SpyStrategy', function() {
describe('#resolveTo', function() {
it('allows a resolved promise to be returned', function(done) {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
spyStrategy = new privateUnderTest.SpyStrategy({
fn: originalFn
});
@@ -144,7 +144,7 @@ describe('SpyStrategy', function() {
it('allows an empty resolved promise to be returned', function(done) {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
spyStrategy = new privateUnderTest.SpyStrategy({
fn: originalFn
});
@@ -162,7 +162,7 @@ describe('SpyStrategy', function() {
describe('#rejectWith', function() {
it('allows a rejected promise to be returned', function(done) {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
spyStrategy = new privateUnderTest.SpyStrategy({
fn: originalFn
});
@@ -179,7 +179,7 @@ describe('SpyStrategy', function() {
it('allows an empty rejected promise to be returned', function(done) {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
spyStrategy = new privateUnderTest.SpyStrategy({
fn: originalFn
});
@@ -196,7 +196,7 @@ describe('SpyStrategy', function() {
it('allows a non-Error to be rejected', function(done) {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
spyStrategy = new privateUnderTest.SpyStrategy({
fn: originalFn
});
@@ -220,7 +220,7 @@ describe('SpyStrategy', function() {
.createSpy('custom strategy')
.and.returnValue(plan),
originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
spyStrategy = new privateUnderTest.SpyStrategy({
fn: originalFn,
customStrategies: {
doSomething: customStrategy
@@ -237,7 +237,7 @@ describe('SpyStrategy', function() {
it("throws an error if a custom strategy doesn't return a function", function() {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
spyStrategy = new privateUnderTest.SpyStrategy({
fn: originalFn,
customStrategies: {
doSomething: function() {
@@ -252,37 +252,32 @@ describe('SpyStrategy', function() {
});
it('does not allow custom strategies to overwrite existing methods', function() {
const spyStrategy = new jasmineUnderTest.SpyStrategy({
const spyStrategy = new privateUnderTest.SpyStrategy({
fn: function() {},
customStrategies: {
exec: function() {}
}
});
expect(spyStrategy.exec).toBe(jasmineUnderTest.SpyStrategy.prototype.exec);
expect(spyStrategy.exec).toBe(privateUnderTest.SpyStrategy.prototype.exec);
});
it('throws an error when a non-function is passed to callFake strategy', function() {
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
spyOn(jasmineUnderTest, 'isAsyncFunction_').and.returnValue(false);
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
expect(function() {
spyStrategy.callFake(function() {});
}).toThrowError(/^Argument passed to callFake should be a function, got/);
expect(function() {
spyStrategy.callFake(function() {});
}).toThrowError(/^Argument passed to callFake should be a function, got/);
spyStrategy.callFake('not a function');
}).toThrowError(
'Argument passed to callFake should be a function, got not a function'
);
});
it('allows generator functions to be passed to callFake strategy', function() {
const generator = function*() {
yield 'ok';
},
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: function() {} });
spyStrategy.callFake(generator);
@@ -292,7 +287,7 @@ describe('SpyStrategy', function() {
it('allows a return to plan stubbing after another strategy', function() {
const originalFn = jasmine.createSpy('original'),
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy = new privateUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.callFake(fakeFn);
let returnValue = spyStrategy.exec();
@@ -309,7 +304,7 @@ describe('SpyStrategy', function() {
it('returns the spy after changing the strategy', function() {
const spy = {},
spyFn = jasmine.createSpy('spyFn').and.returnValue(spy),
spyStrategy = new jasmineUnderTest.SpyStrategy({ getSpy: spyFn });
spyStrategy = new privateUnderTest.SpyStrategy({ getSpy: spyFn });
expect(spyStrategy.callThrough()).toBe(spy);
expect(spyStrategy.returnValue()).toBe(spy);