Skip to content

Commit

Permalink
test: improve unmounted app check
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Sep 4, 2024
1 parent 2592a34 commit 57434d8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions test/e2e/components/Application.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { render } from '@testing-library/react';
import { useEffect } from 'react';

import { Application } from '../../../src/components/Application';
import { isAppMounted } from '../../utils/isAppMounted';
import { useApplication } from '../../../src/hooks/useApplication';

describe('Application', () => {
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('Application', () => {

unmount();

await expect.poll(() => Boolean(testApp.renderer && testApp.stage)).toBeFalsy();
await expect.poll(() => isAppMounted(testApp)).toBeFalsy();
});

it('unmounts during init', async () => {
Expand Down Expand Up @@ -106,7 +107,7 @@ describe('Application', () => {

unmount();

await expect.poll(() => Boolean(testApp.renderer && testApp.stage)).toBeFalsy();
await expect.poll(() => isAppMounted(testApp)).toBeFalsy();
});
});
});
19 changes: 19 additions & 0 deletions test/utils/getAppRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { type Application as PixiApplication } from 'pixi.js';
import { roots } from '../../src/core/roots';
import { type Root } from '../../src/typedefs/Root';

export function getAppRoot(app: PixiApplication)
{
let root: Root | undefined;

for (const oRoot of roots.values())
{
if (oRoot.applicationState.app === app)
{
root = oRoot;
break;
}
}

return root;
}
22 changes: 22 additions & 0 deletions test/utils/isAppMounted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { type Application as PixiApplication } from 'pixi.js';
import { getAppRoot } from './getAppRoot';

export function isAppMounted(app: PixiApplication)
{
if (app.stage === null)
{
return false;
}

if (app.renderer === null)
{
return false;
}

if (typeof getAppRoot(app) === 'undefined')
{
return false;
}

return true;
}

0 comments on commit 57434d8

Please sign in to comment.