So I am new to writing test and I am having an issue I do not quite understand. I keep getting this syntax error "
SyntaxError: Unexpected end of input
95 | })
96 | describe('Renders Home Page', () => {
> 97 | test('Intercept Request', async () => {
| ^
98 | await page.waitForSelector('body > #root > .default-blank-container > .default-login > button')
99 | const navigationPromise = page.waitForNavigation({
100 | waitUntil: ['networkidle2']
Here is the Current Code I am running. The code runs, and logs in then shuts down with this syntax error that VS code is not catching. I have found I ran into this issue several times. please help me bridge this gap of understanding. thanks! any help is much appreciated
// // /*
// // Testing Using jest puppeteer. Test ENV Preconfigured so no need to import puppeteer. See More With Documentation at
// // Testing Documentation- https://github.com/smooth-code/jest-puppeteer
// // */
const timeout = 26000;
var hasLoggedIn = false;
var user = 'someuser'
var pw = 'somepassword'
beforeAll(async () => {
jest.setTimeout(200000)
await page.goto('http://localhost:5000/login', {
waitUntil: 'networkidle2'
});
page.setViewport({
width: 0,
height: 0
})
page.setRequestInterception(true)
page.on('request', interceptedRequest => {
if (interceptedRequest.url().endsWith('v1/user')) {
hasLoggedIn ?
interceptedRequest.respond({
content: 'application/json',
headers: {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({
success: true,
user: {
created_at: "2019-01-01T00:00:00.000Z",
email: "myemail.com",
firstname: "Dev",
lastname: "Eddoen",
permission: [],
session: "_e0d7db00-7a93-0137-e0dd-03bfe620dd3b",
updated_at: "2019-01-01T00:00:00.000Z",
_v: 0,
_id: "123456789"
}
})
}) :
request.respond({
content: 'application/json',
headers: {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({
success: false
})
})
} else if (interceptedRequest.url().endsWith(`/v1/login`)) {
var url = request.url()
url = url.split("=")
interceptedRequest.respond({
status: 302,
headers: {
"Access-Control-Allow-Origin": "*",
"Location": "http://localhost:5000",
"set-cookie": `userKey=${url[1]}`
}
}),
hasLoggedIn = true
} else {
interceptedRequest.continue();
}
})
})
describe('Renders Home Page', () => {
test('Intercept Request', async () => {
await page.waitForSelector('body > #root > .default-blank-container > .default-login > button')
const navigationPromise = page.waitForNavigation({
waitUntil: ['networkidle2']
})
page.authenticate({
username: user,
password: pw
})
await page.click('body > #root > .default-blank-container > .default-login > button')
await navigationPromise
await page.waitForSelector('button.mui-btn.mui-btn--small.mui-btn--raised')
const logout = await page.evaluate(el => el.innerHTML, await page.$('button.mui-btn.mui-btn--small.mui-btn--raised'));
expect(logout).toContain('Settings')
});
})
Aucun commentaire:
Enregistrer un commentaire