在拦截请求时,只有第一个之后的请求才会受到影响。 我认为这是因为如果这样我不愿意这样做。 我试着等待domcontent加载,但是那也不起作用。
describe('index', () => {
let page;
let testData;
beforeAll(async () => {
jest.setTimeout(30000);
const browser = await puppeteer.launch({
headless: false,
slowMo: 100,
args: ['--windows-size=1920,1080']
});
testData = {
page: 1,
pages: 7,
tv_shows: [
{
name: 'Star Wars:The Clone Wars'
}
]
};
page = await browser.newPage();
await page.goto('http://localhost:1234/');
await page.setRequestInterception(true);
await page.on('request', request => {
request.respond({
content: 'application/json',
headers: { 'Access-Control-Allow-Origin': '*' },
body: JSON.stringify(testData)
});
});
});
describe('searching for job', () => {
let showCard;
beforeAll(async () => {
await page.waitForSelector('#search-form');
await page.type('input[name=title]', 'star wars');
await page.$eval('#submit-btn', btn => btn.click());
showCard = await page.waitForSelector('.card');
});
it('element with class showCard should exist', () => {
expect(showCard).toBeTruthy();
});
});
});