I'm currently experimenting with testing a function in Jasmine that has the following definition:
let main = new function() {
this.addIframe = () => {
try {
$("body").append("<iframe id='myiframe'> </iframe>");
return true;
} catch (err) {
dosomthing();
return false;
}
};
};
This specific type of function definition is necessary for setting up spies and other test suite configurations later on. However, I've encountered an issue when attempting to test the return statement using the code below:
describe("Function AddIframe", ()=> {
it("should return true if opened iframe",()=>{
expect(addIframe()).toBe(true);
});
The problem lies in getting 'Undefined' as a result, which I understand is due to how JavaScript operates with its two-step process.
I have tried switching to a conventional function definition but require the current format for my other tests. Even exploring putting it inside an object did not resolve the 'undefined' error, even when utilizing `this.method`.
If anyone can provide insight into what I might be overlooking here or suggest a workaround, I would greatly appreciate it.