admin管理员组文章数量:1404927
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","joe"
);
An error appear : Expected 1 arguments, but got 2.
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.","joe"
);
An error appear : Expected 1 arguments, but got 2.
Share Improve this question asked Dec 15, 2021 at 7:35 wewe wewewewe wewe 412 silver badges8 bronze badges 1-
1
createUser()
is expecting aUser
object as parameter. But you're passing two strings. What you want would beLogin.createUser({ url: "google.", email: "joe" });
– Hao Wu Commented Dec 15, 2021 at 7:38
2 Answers
Reset to default 4The 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.',
email: 'joe'
})
BTW why are you using "interface" and not "type" here? type is more mon for defining object shapes and interface is often used to describe behaviours
your createUser function was declared with only one parameter but when you call this method you passed two-parameter. to fix this you need to pass user object
本文标签: javascriptTypeScript Expected 1 argumentsbut got 2Stack Overflow
版权声明:本文标题:javascript - TypeScript Expected 1 arguments, but got 2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744866745a2629389.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论