はじめに 「Nuxt on Dockerにて、Jest + Puppeteer でE2Eテスト環境をセットアップする」でJest + PuppeteerでE2Eテストをする環境を整えました。 この記事では、実際にE2Eテストを記述するときに使う操作や検証のコードをまとめておきます。 自分が使ったコードを書いていくので、順次増えていく予定。 基本 テストファイル内の基本構文は以下のとおりです。 describe('テストスイート名', () => { test('テストケース名', async () => { await page.goto('http://localhost:3000') // 操作とか await expect(page.url()).toBe('http://localhost:3000') // 検証とか }) }) describeとtest 1つのファイルには1つ
![Jest + PuppeteerのE2Eテストで使うコード集](https://cdn-ak-scissors.b.st-hatena.com/image/square/915b26d17a03dcb2a9794d84fcee317d88e093d4/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--rS1ij5Wa--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3AJest%252520%25252B%252520Puppeteer%2525E3%252581%2525AEE2E%2525E3%252583%252586%2525E3%252582%2525B9%2525E3%252583%252588%2525E3%252581%2525A7%2525E4%2525BD%2525BF%2525E3%252581%252586%2525E3%252582%2525B3%2525E3%252583%2525BC%2525E3%252583%252589%2525E9%25259B%252586%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3Aasato%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3plbm4tdXNlci11cGxvYWQvYXZhdGFyL2Y1YTcyMmY5ZmUuanBlZw%3D%3D%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)