fix: fix integration tests

This commit is contained in:
Satyajit Sahoo
2021-05-16 05:04:49 +02:00
parent 22b7c3f6c1
commit 211f1f2c0e
4 changed files with 60 additions and 27 deletions

View File

@@ -4,42 +4,41 @@ beforeEach(async () => {
await page.click('[data-testid=LinkComponent]');
});
it('loads the article page', async () => {
expect(await page.evaluate(() => location.pathname + location.search)).toBe(
'/link-component/article/gandalf'
);
const getPageInfo = async () => ({
url: await page.evaluate(() => location.pathname + location.search),
title: await page.evaluate(() => document.title),
heading: (await page.accessibility.snapshot())?.children?.find(
(it) => it.role === 'heading'
)?.name,
});
expect(
((await page.accessibility.snapshot()) as any)?.children?.find(
(it: any) => it.role === 'heading'
)?.name
).toBe('Article by Gandalf');
it('loads the article page', async () => {
const { url, title, heading } = await getPageInfo();
expect(url).toBe('/link-component/article/gandalf');
expect(title).toBe('Article by Gandalf - React Navigation Example');
expect(heading).toBe('Article by Gandalf');
});
it('goes to the album page and goes back', async () => {
await page.click('[href="/link-component/music"]');
expect(await page.evaluate(() => location.pathname + location.search)).toBe(
'/link-component/music'
);
{
const { url, title, heading } = await getPageInfo();
expect(
((await page.accessibility.snapshot()) as any)?.children?.find(
(it: any) => it.role === 'heading'
)?.name
).toBe('Albums');
expect(url).toBe('/link-component/music');
expect(title).toBe('Albums - React Navigation Example');
expect(heading).toBe('Albums');
}
await page.click('[aria-label="Article by Gandalf, back"]');
await page.waitForNavigation();
expect(await page.evaluate(() => location.pathname + location.search)).toBe(
'/link-component/article/gandalf'
);
{
const { url, title, heading } = await getPageInfo();
expect(
((await page.accessibility.snapshot()) as any)?.children?.find(
(it: any) => it.role === 'heading'
)?.name
).toBe('Article by Gandalf');
expect(url).toBe('/link-component/article/gandalf');
expect(title).toBe('Article by Gandalf - React Navigation Example');
expect(heading).toBe('Article by Gandalf');
}
});

View File

@@ -43,6 +43,7 @@
"@types/cheerio": "^0.22.28",
"@types/jest-dev-server": "^4.2.0",
"@types/koa": "^2.13.1",
"@types/mock-require": "^2.0.0",
"@types/node-fetch": "^2.5.9",
"@types/react": "~16.9.35",
"@types/react-dom": "~16.9.8",
@@ -54,6 +55,7 @@
"expo-cli": "^4.4.4",
"jest": "^26.6.3",
"jest-dev-server": "^4.4.0",
"mock-require": "^3.0.3",
"mock-require-assets": "^0.0.1",
"node-fetch": "^2.6.1",
"nodemon": "^2.0.6",

View File

@@ -1,5 +1,6 @@
import 'mock-require-assets';
import mock from 'mock-require';
import Module from 'module';
// We need to make sure that .web.xx extensions are resolved before .xx
@@ -10,3 +11,14 @@ Module._extensions = Object.fromEntries(
return b[0].split('.').length - a[0].split('.').length;
})
);
// Set __DEV__ that expo needs
// @ts-expect-error
global.__DEV__ = process.env.NODE_ENV !== 'production';
// Reanimated doesn't support SSR :(
mock(
'react-native-reanimated',
// eslint-disable-next-line import/no-commonjs
{ ...require('react-native-reanimated/mock').default, call() {} }
);

View File

@@ -3717,6 +3717,13 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==
"@types/mock-require@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/mock-require/-/mock-require-2.0.0.tgz#57a4f0db0b4b6274f610a2d2c20beb3c842181e1"
integrity sha512-nOgjoE5bBiDeiA+z41i95makyHUSMWQMOPocP+J67Pqx/68HAXaeWN1NFtrAYYV6LrISIZZ8vKHm/a50k0f6Sg==
dependencies:
"@types/node" "*"
"@types/node-fetch@^2.5.9":
version "2.5.9"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.9.tgz#c04a12115aa436f189e39579272b305e477621b4"
@@ -9069,6 +9076,11 @@ gensync@^1.0.0-beta.1, gensync@^1.0.0-beta.2:
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==
get-caller-file@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"
integrity sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==
get-caller-file@^2.0.1, get-caller-file@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
@@ -12847,6 +12859,14 @@ mock-require-assets@^0.0.1:
resolved "https://registry.yarnpkg.com/mock-require-assets/-/mock-require-assets-0.0.1.tgz#94136f70e5b009c52c2df3b45724d15ab4f0cb98"
integrity sha1-lBNvcOWwCcUsLfO0VyTRWrTwy5g=
mock-require@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/mock-require/-/mock-require-3.0.3.tgz#ccd544d9eae81dd576b3f219f69ec867318a1946"
integrity sha512-lLzfLHcyc10MKQnNUCv7dMcoY/2Qxd6wJfbqCcVk3LDb8An4hF6ohk5AztrvgKhJCqj36uyzi/p5se+tvyD+Wg==
dependencies:
get-caller-file "^1.0.2"
normalize-path "^2.1.1"
mockdate@^3.0.2:
version "3.0.5"
resolved "https://registry.yarnpkg.com/mockdate/-/mockdate-3.0.5.tgz#789be686deb3149e7df2b663d2bc4392bc3284fb"
@@ -15280,7 +15300,7 @@ react-native-web@~0.15.0:
prop-types "^15.6.0"
react-timer-mixin "^0.13.4"
"react-native@https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz", react-native@~0.63.2, react-native@~0.63.4:
"react-native@https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz", react-native@~0.63.4:
version "0.63.4"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.63.4.tgz#2210fdd404c94a5fa6b423c6de86f8e48810ec36"
integrity sha512-I4kM8kYO2mWEYUFITMcpRulcy4/jd+j9T6PbIzR0FuMcz/xwd+JwHoLPa1HmCesvR1RDOw9o4D+OFLwuXXfmGw==