toSaveSnapshot-toSaveImageSnapshot-template.test.js 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
describe('toSaveSnapshot & toSaveImageSnapshot template', () => {
  beforeAll(async () => {
    let page = await program.reLaunch('/pages/tabBar/component');
    await page.waitFor(1000);
  })

  it('test toSaveSnapshot 1', async () => {
    const text1 = 'test-toSaveSnapshot-1-1-' + Date.now()
    expect(text1).toSaveSnapshot()
    const text2 = 'test-toSaveSnapshot-1-2-' + Date.now()
    expect(text2).toSaveSnapshot()
  })
  
  it('test toSaveSnapshot 2', async () => {
    const text1 = 'test-toSaveSnapshot-2-1-' + Date.now()
    expect(text1).toSaveSnapshot({
      customSnapshotsDir: `./customDir/__file_snapshots__`,
      fileName: 'test-toSaveSnapshot-2-1.txt'
    })
    const text2 = 'test-toSaveSnapshot-2-2-' + Date.now()
    expect(text2).toSaveSnapshot({
      customSnapshotsDir: './customDir/__file_snapshots__'
    })
    
    const text3 = 'test-toSaveSnapshot-2-3-' + Date.now()
    expect(text3).toSaveSnapshot({
DCloud-WZF's avatar
DCloud-WZF 已提交
27
      fileName: 'test-toSaveSnapshot-2-3.json'
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    })
  })
  
  it('test toSaveImageSnapshot 1', async () => {
    const img1 = await program.screenshot();
    expect(img1).toSaveImageSnapshot()

    const img2 = await program.screenshot();
    expect(img2).toSaveImageSnapshot()
  })

  it('test toSaveImageSnapshot 2', async () => {
    const img1 = await program.screenshot();
    expect(img1).toSaveImageSnapshot({
      customSnapshotsDir: './customDir/__image_snapshots__',
      customSnapshotIdentifier() {
        return 'test-toSaveImageSnapshot-2-1.png';
      },
    })

    const img2 = await program.screenshot();
    expect(img2).toSaveImageSnapshot({
      customSnapshotsDir: './customDir/__image_snapshots__',
    })
    
    const img3 = await program.screenshot();
    expect(img3).toSaveImageSnapshot({
      customSnapshotIdentifier() {
        return 'test-toSaveImageSnapshot-2-3.png';
      },
    })
  })
});