我正在尝试查看 mailslurp 是否可以满足我们在用户注册我们网站上的课程后检索电子邮件中的链接的需求。
我正在使用此处找到的示例代码:https ://www.mailslurp.com/examples/testcafe-mfa-user-sign-up/
我从示例代码中唯一改变的是我们如何为我们的 mailslurp 帐户调用 API KEY。
示例代码运行良好,直到进入“waitForLatestEmail”步骤。它出错并指向 mailslurp 代码
1) TypeError: since.toISOString is not a function
Browser: Chrome 92.0.4515.159 / macOS 10.15.7
14532 | }
14533 | if (inboxId !== undefined) {
14534 | localVarQueryParameter['inboxId'] =
inboxId;
14535 | }
14536 | if (since !== undefined) {
> 14537 | localVarQueryParameter['since'] =
since.toISOString();
14538 | }
14539 | if (sort !== undefined) {
14540 | localVarQueryParameter['sort'] = sort;
14541 | }
14542 | if (timeout !== undefined) {
at Object.waitForLatestEmail
(/Users/justin/Documents/cf2-test-cafe-poc/node_modules/mailslurp-client/dist/generated/api.js:14537:57)
at Object.waitForLatestEmail
(/Users/justin/Documents/cf2-test-cafe-poc/node_modules/mailslurp-client/dist/generated/api.js:14820:98)
at WaitForControllerApi.waitForLatestEmail
(/Users/justin/Documents/cf2-test-cafe-poc/node_modules/mailslurp-client/dist/generated/api.js:15074:67)
at <anonymous>
(/Users/justin/Documents/cf2-test-cafe-poc/dev_tests/mail_slurp.js:60:50)
at asyncGeneratorStep
(/Users/justin/Documents/cf2-test-cafe-poc/dev_tests/mail_slurp.js:3:142)
at _next
(/Users/justin/Documents/cf2-test-cafe-poc/dev_tests/mail_slurp.js:3:480)
有没有人遇到过这个问题,问题是如何解决的?
当前测试文件:
import { Selector } from 'testcafe'
import { MailSlurp } from 'mailslurp-client'
import { mail_slurp } from '../constants'
let mailslurp
const api_key = mail_slurp.api_key
const password = "test-password"
fixture `mail_slurp`
.page `https://playground.mailslurp.com`
.before(
async(_) => {
if(!api_key){
throw "No Mailslurp API KEY defined"
}
mailslurp = new MailSlurp({ apiKey: api_key })
}
)
test('Grab magic link from email', async t => {
// create email address for a test user
const inbox = await mailslurp.inboxController.createInbox();
// load the page and click sign up
await t
.expect(Selector("title").innerText)
.eql("React App")
.click(Selector("[data-test=sign-in-create-account-link]"));
// wait for sign up form then fill with email address and sign up
const emailInput = await Selector('[name="email"]')();
await t
.typeText(emailInput, inbox.emailAddress)
.typeText(Selector('[name="password"]'), password)
.click(Selector("[data-test=sign-up-create-account-button]"));
// **Step where the test fails**
// wait for verification code to arrive to email then extract code
const email = await mailslurp.waitController.waitForLatestEmail(
inbox.id,
30000,
true
);
// **Not getting to this code**
// use regex to extract the confirmation code which is 6 digits
const code = /([0-9]{6})$/.exec(email.body)[1];
// now enter code to confirm
await t
.typeText(Selector('[name="code"]'), code)
.click(Selector('[data-test="confirm-sign-up-confirm-button"]'));
// now sign up
const username = await Selector('[name="username"]')();
await t
.typeText(username, inbox.emailAddress)
.typeText(Selector('[name="password"]'), password);
const signIn = await Selector("[data-test=sign-in-sign-in-button]")();
await t.click(signIn);
// wait for sign up
const h1 = await Selector("h1")();
await t.expect(h1.innerText).eql("Welcome");
})
版本:
mailslurp 客户端:13.2.0
测试咖啡馆:1.15.2
节点:16.5.0
npm:7.20.5