It is possible to detect the usage of {}
in JS code with test framework Jasmine by spying on a certain internal JS method / property?
For example:
describe('tests', () => {
it('test1', async () => {
const spy = spyOn(Object, '???').and.callThrough();
const x = {};
expect(spy).toHaveBeenCalled();
});
it('test2', async () => {
const spy = spyOn(Object, '???').and.callThrough();
const x = null || {};
expect(spy).toHaveBeenCalled();
});
});
The spy
should only be called when creating an object with {}
, not when creating it with Object.create(null)
. So it may be something related to inheritance from the global JS object prototype that could help.