so I have this nightmare code that worked perfectly fine and I put it into a class. However it started throwing promise errors :-( (without the fun() function it works fine.
class test {
constructor() {
this.init(() => {
this.start()
})
}
init() {
this.nightmare = new Nightmare({
show: true,
typeInterval: 20,
openDevTools: {
detach: true
}
});
}
async start() {
await this.nightmare
.useragent(userAgent)
.goto("https://www.yahoo.com")
fun();
async function fun() {
await this.nightmare.goto('https://google.com')
}
}
}
new test().start();
The error is:
(node:1101) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'nightmare' of undefined
(node:1101) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
await this.nightmare.goto('https://google.com')
in atry catch
– dzmawait fun();
? and what happens if you move the call after the function initialization? – Get Off My Lawn