You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Observer the below setup.
If code which calls a spy is running with vm.runInNewContext (something I often do to stub out modules included through require in the code I am testing), jasmine.any(Array) returns false when passing []. Interestingly new Array() works.
It seems like jasmine.any must be relying on isntanceof Array because [] instanceof Array will return false inside vm.runInNewContext where Array.isArray([]) will function correctly.
Perhaps there is a better way to implement jasmine.any(Array) or some other test I can use?
const vm = require('vm');
describe('jasmine.any(Array)', function() {
var mockFunc;
beforeEach(function() {
mockFunc = jasmine.createSpy();
});
it('handles instanceof Array normally', function() {
// this will pass
mockFunc([])
expect(mockFunc).toHaveBeenCalled();
expect(mockFunc).toHaveBeenCalledWith(jasmine.any(Array));
});
it('handles instanceof Array normaly with vm.runInNewContext when new Array is used', function() {
// this will pass
vm.runInNewContext('mockFunc(new Array())', { mockFunc: mockFunc, Array: Array });
expect(mockFunc).toHaveBeenCalled();
expect(mockFunc).toHaveBeenCalledWith(jasmine.any(Array));
});
it('handles instanceof Array normaly with vm.runInNewContext when [] is used', function() {
// this will fail
vm.runInNewContext('mockFunc([])', { mockFunc: mockFunc, Array: Array });
expect(mockFunc).toHaveBeenCalled();
expect(mockFunc).toHaveBeenCalledWith(jasmine.any(Array));
});
});
The text was updated successfully, but these errors were encountered:
Observer the below setup.
If code which calls a spy is running with
vm.runInNewContext
(something I often do to stub out modules included through require in the code I am testing),jasmine.any(Array)
returns false when passing[]
. Interestinglynew Array()
works.It seems like jasmine.any must be relying on isntanceof Array because
[] instanceof Array
will return false inside vm.runInNewContext whereArray.isArray([])
will function correctly.Perhaps there is a better way to implement jasmine.any(Array) or some other test I can use?
The text was updated successfully, but these errors were encountered: