Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed May 25, 2023
1 parent 231d23e commit 3744a02
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export function createTexture(base: BaseTexture, loader: Loader, url: string)
{
const texture = new Texture(base);

// make sure to nuke the promise if a texture is destroyed..
texture.baseTexture.on('destroy', () =>
// remove the promise from the loader and the url from the cache when the texture is destroyed
texture.baseTexture.once('destroy', () =>
{
delete loader.promiseCache[url];
Cache.remove(url);
Expand Down
25 changes: 25 additions & 0 deletions packages/assets/test/assets.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,29 @@ describe('Assets', () =>
Assets.setPreferences({ preferWorkers: true });
expect(loadTextures.config.preferWorkers).toBe(true);
});

it('should remove the asset from the cache when destroyed', async () =>
{
await Assets.init({
basePath,
});

const url = 'textures/bunny.png';
const texture1 = await Assets.load(url);

expect(Assets.cache.has(url)).toBeTrue();

texture1.destroy(true);

expect(Assets.cache.has(url)).toBeFalse();

const texture2 = await Assets.load(url);

expect(Assets.cache.has(url)).toBeTrue();
expect(texture2).not.toBe(texture1);

texture2.destroy(true);

expect(Assets.cache.has(url)).toBeFalse();
});
});

0 comments on commit 3744a02

Please sign in to comment.