Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
168
rated 0 times [  172] [ 4]  / answers: 1 / hits: 5949  / 2 Years ago, wed, december 15, 2021, 12:00:00

What's wrong with my function createUser()?
Why I can't put params in Smoke.ts ?


Login.ts :


interface User {
url: string,
email: string,
}

class Test{
async createUser(user: User) {
await Page.setUrl(user.url);
await Page.setEmail(user.email);



}
}

Smoke.ts


test("Smoke Test", async (t) => {
console.log("Starting test");
await Login.createUser(
"google.com","joe"
);

An error appear : Expected 1 arguments, but got 2.


More From » typescript

 Answers
4

The method createUser is expecting an object with the following shape:
{
url: string,
email: string,
}


And you are passing a string as first parameter and another string as the second parameter.


you should be passing an object like this:


createUser({ 
url: 'google.com',
email: 'joe'
})

BTW why are you using "interface" and not "type" here?
type is more common for defining object shapes and interface is often used to describe behaviours


[#583] Tuesday, December 7, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaceyr

Total Points: 510
Total Questions: 97
Total Answers: 116

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
;